Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
aiida.cmdline.utils.decorators.load_backend_if_not_loaded
(#4878)
The function incorrectly used the `PROFILE` global variable to determine whether the database backend environment had been loaded. This variable is set as soon as a profile is loaded, however, this does not automatically mean that the database environment is also loaded. These two actions are separate on purpose such that a profile can be loaded without having to load the backend, since that is an expensive operation and is not always necessary. This bug meant that sometimes the backend would actually not be loaded even though the `with_dbenv` decorator was correctly used. This affects, among other things, all CLI commands that rely on the backend being loaded but having no code in its execution path that will automatically load the backend, such as `verdi archive import`. Any commands that deal with the ORM still work, since loading any ORM entity will automatically load the backend of the current profile if not already done. Since the import functionality circumvents the ORM, it didn't have this failsafe operation. Finally, the bug was not noticed by the unittests because they run in an environment where the database backend is loaded anyway for the test profile effectively hiding the bug of the `load_backend_if_not_loaded` method.
- Loading branch information