Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unintentional creation of defaultdict key by __getitem__ calls #1110

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/raiden_libs/user_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ def add_userids_for_address(self, address: Address, user_ids: Iterable[str]) ->

def get_userids_for_address(self, address: Address) -> Set[str]:
"""Return all known user ids for the given ``address``."""
if not self.is_address_known(address):
return set()
return self._address_to_userids[address]
return self._address_to_userids.get(address, set())

def get_userid_presence(self, user_id: str) -> UserPresence:
"""Return the current presence state of ``user_id``."""
Expand Down Expand Up @@ -193,7 +191,7 @@ def track_address_presence(
self.get_address_reachability_state(address).reachability
!= AddressReachability.UNKNOWN
)
no_new_user_ids = user_ids.issubset(self._address_to_userids[address])
no_new_user_ids = user_ids.issubset(self._address_to_userids.get(address, set()))
if state_known and no_new_user_ids:
return

Expand Down Expand Up @@ -245,7 +243,7 @@ def _maybe_address_reachability_changed(self, address: Address) -> None:
# these users and uses the "best" presence. IOW, if there is at least one
# Matrix user that is reachable, then the Raiden node is considered
# reachable.
userids = self._address_to_userids[address].copy()
userids: Set[str] = self._address_to_userids.get(address, set()).copy()
presence_to_uid = defaultdict(list)
for uid in userids:
presence_to_uid[self._userid_to_presence.get(uid)].append(uid)
Expand Down