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

resetting default User cache #3462

Closed
ltalirz opened this issue Oct 23, 2019 · 2 comments · Fixed by #3319
Closed

resetting default User cache #3462

ltalirz opened this issue Oct 23, 2019 · 2 comments · Fixed by #3319
Assignees
Milestone

Comments

@ltalirz
Copy link
Member

ltalirz commented Oct 23, 2019

Since the default user of an AiiDA profile is requested a lot, we've introduced a cache for this property:

def get_default(self):
"""
Get the current default user
:return: The default user
:rtype: :class:`aiida.orm.User`
"""
if self._default_user is self.UNDEFINED:
from aiida.manage.configuration import get_profile
profile = get_profile()
email = profile.default_user
if not email:
self._default_user = None
try:
self._default_user = self.get(email=email)
except (exceptions.MultipleObjectsError, exceptions.NotExistent):
self._default_user = None
return self._default_user

However, short of resetting the manager, there currently doesn't seem to be a way to reset this cache, as one might want to do, for example, after setting a new default user programmatically, deleting the default user, etc.

Resetting this cache could be done at two levels:

  1. A specific command for the User.objects collection that resets its _default_user property
  2. A generic reset() method for objects - objects are loaded lazily and so you can add a generic method
        @classmethod
        def reset(cls):
            cls._COLLECTIONS = datastructures.LazyStore()
    to aiida.orm.entities.Collection
    This would allow to do User.objects.reset() (same for XXX.objects.reset()).

I'm leaning towards the second option - what do you guys think?

@sphuber
@giovannipizzi

@sphuber
Copy link
Contributor

sphuber commented Oct 25, 2019

The second solution you proposed, as implemented, will not only reset the collection of that particular entity and backend, but of all collections that have been instantiated. This is not what we want. I would for now go for a specific reset on the default user on the User collection. Anyway, that is the only collection with real state I think.

@ltalirz
Copy link
Member Author

ltalirz commented Oct 25, 2019

The second solution you proposed, as implemented, will not only reset the collection of that particular entity and backend, but of all collections that have been instantiated.

Oops - you're right ;-)

Instead of hacking a specific solution for the User, one could probably still do something like this (seems to work)?

    def reset(self):
        """
        Remove lazily constructed collection instance.

        Removes lazily constructed collection instance from LazyStore (constructed again upon next request).
        Useful to clear any internal caches of the collection.
        """
        self._COLLECTIONS.pop((self.entity_type, self.backend))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants