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

👌 IMPROVE: Move default user caching to StorageBackend #5460

Merged
merged 6 commits into from
Apr 26, 2022

Conversation

chrisjsewell
Copy link
Member

Currently it is cached on the UserCollection,
but this means that, on profile switching,
it would return a user associated with the wrong backend instance.

@ramirezfranciscof ramirezfranciscof added this to the v2.0.0 milestone Apr 6, 2022
@sphuber sphuber mentioned this pull request Apr 12, 2022
@sphuber
Copy link
Contributor

sphuber commented Apr 12, 2022

Same as for #5461 if you add a quick test, we should merge this for the release since it is a known bug of the new profile switching

Currently it is cached on the `UserCollection`,
but this means that, on profile switching,
it would return a user associated with the wrong backend instance.
@chrisjsewell
Copy link
Member Author

@sphuber this is good to go

@@ -155,7 +155,7 @@ def __init__(
raise ValueError('Group label must be provided')

backend = backend or get_manager().get_profile_storage()
user = user or users.User.collection(backend).get_default()
user = user if user else backend.default_user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the change from user or to user if user else necessary? Does that change anything? I think the or notation is clearer and is also used in the line before.

Comment on lines 176 to 178
results = query.all(flat=True)
if results:
self._default_user = results[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was line 178 being tested? Shouldn't all(flat=True) just return the User or None? So line 178 indexing [0] would except no? Anyway, I think we should just use first here.

Suggested change
results = query.all(flat=True)
if results:
self._default_user = results[0]
self._default_user = query.first(flat=True)

@@ -31,7 +31,6 @@ def _entity_base_cls() -> Type['User']:

def __init__(self, entity_class: Type['User'], backend: Optional['StorageBackend'] = None) -> None:
super().__init__(entity_class=entity_class, backend=backend)
self._default_user: Optional[User] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overridden constructor is now pointless, might as well get rid of it entirely

@chrisjsewell chrisjsewell merged commit ca6b324 into aiidateam:develop Apr 26, 2022
@chrisjsewell chrisjsewell deleted the default-user branch April 26, 2022 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants