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

Manager.load_profile: do not load default profile if other already loaded #5383

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Feb 23, 2022

Fixes #5381

The Manager.load_profile method was loading the default profile if no
explicit profile name was specified, even if another profile was already
loaded. This is violating the note in the docstring that if a profile is
already loaded, not specifying an explicit profile to be loaded should
be a no-op.

This bug was manifesting itself in verdi where the --profile option
was effectively ignored if a profile other than the default was
specified for a command that uses the load_dbenv decorator. This is
because the ProfileParamType would correctly load the profile
specified by the option, but then the load_dbenv decorator would call
aiida.cmdline.utils.decorators.load_backend_if_not_loaded which would
call Manager.load_profile without specifying a profile, and so the
default profile would be loaded.

@sphuber
Copy link
Contributor Author

sphuber commented Feb 23, 2022

Since this is really a problem of Manager.load_profile maybe the unit test should also be tested directly on that method and not on the load_dbenv_if_not_loaded wrapper function. But the latter should really also be tested. But I would essentially end up duplicating the test. Should I do that nevertheless?

@sphuber sphuber requested a review from chrisjsewell February 23, 2022 10:07
@@ -105,15 +105,14 @@ def load_profile(self, profile: Union[None, str, 'Profile'] = None, allow_switch
from aiida.common.log import configure_logging
from aiida.manage.configuration.profile import Profile

if profile is None and self._profile:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if profile is None and self._profile:
# If a profile is already loaded and no explicit profile is specified, we do nothing
if profile is None and self._profile:

Comment on lines 113 to 116
# If a profile is loaded and the specified profile name is that of the currently loaded, do nothing
if self._profile and (self._profile.name == profile.name):
return self._profile

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this needs to be removed: it handles for example:

load_profile('x')
load_profile('x')  # no-op

@chrisjsewell
Copy link
Member

Should I do that nevertheless?

I think its ok not to

…loaded

The `Manager.load_profile` method was loading the default profile if no
explicit profile name was specified, even if another profile was already
loaded. This is violating the note in the docstring that if a profile is
already loaded, not specifying an explicit profile to be loaded should
be a no-op.

This bug was manifesting itself in `verdi` where the `--profile` option
was effectively ignored if a profile other than the default was
specified for a command that uses the `load_dbenv` decorator. This is
because the `ProfileParamType` would correctly load the profile
specified by the option, but then the `load_dbenv` decorator would call
`aiida.cmdline.utils.decorators.load_backend_if_not_loaded` which would
call `Manager.load_profile` without specifying a profile, and so the
default profile would be loaded.
@sphuber sphuber force-pushed the fix/5381/manager-load-profile branch from 18311c4 to 7b50516 Compare February 23, 2022 10:18
@chrisjsewell
Copy link
Member

chrisjsewell commented Feb 23, 2022

Perhaps we need to increase the allowed verdi load time from 0.4 to 0.41. For python 3.8, it often can be about this.
I don't think there has been any obvious changes to degrade the load time, in fact I actually changed the check to disallow even loading aiida.storage (formerly aiida.backends)

@sphuber sphuber merged commit b0b7261 into aiidateam:develop Feb 23, 2022
@sphuber sphuber deleted the fix/5381/manager-load-profile branch February 23, 2022 12:35
@sphuber
Copy link
Contributor Author

sphuber commented Feb 23, 2022

Perhaps we need to increase the allowed verdi load time from 0.4 to 0.41.

Yeah, it is indeed a bit annoying, but it would be better still to see if we can get the load time to decrease. I personally at least find it very annoying to have lag in the tab-completion.

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.

The --profile option for verdi is no longer respected and always loads the default profile
2 participants