aiidalab / aiidalab-qe

AiiDAlab App for Quantum ESPRESSO
https://aiidalab-qe.readthedocs.io/
MIT License
9 stars 14 forks source link

Improve code setup #724

Open danielhollas opened 1 month ago

danielhollas commented 1 month ago

We're now having discussions about this in three different places, so creating issue just for this.

I think this comment from Seb and subsequent discussion is critical:

@sphuber would you mind taking a look if the changes here make sense? I am not super familiar in how aiida-core handles User instances.

I had a look but I don't understand what the changes to fetching the default user should do. First of, User.objects is deprecated, and User.collection should be used instead. So the PR changes to use the deprecated version. The current use is correct. To get the default user, User.collection.get_default() is correct. The only tricky part here is that this default is cached on the StorageBackend. So if the default user is changed, this needs to be reset through StorageBackend.reset_default_user. This is done automatically through Manager.set_default_user_email but not if you go directly through Profile.set_default_user_email.

If you want to manually query for a user given an email, I would recommend User.collection.get(email='email'). It is concise and closest in syntax to User.colelction.get_default()

Is seems to me that using StorageBackend.reset_default_user could be used to get rid of the cached User instance, before setting up the codes.

danielhollas commented 1 month ago

cc @unkcpz @superstar54