Skip to content

Commit

Permalink
Remove with_dbenv use in aiida.orm
Browse files Browse the repository at this point in the history
This forces the import of `aiida.cmdline` in `aiida.orm` which doesn't
just slow down, but also is conceptually wrong. The problem of the
`with_dbenv` decorator is also that it cannot be imported inside a
method to avoid the import cost when importing `aiida.orm` but has to be
imported at the top in order to be used.
  • Loading branch information
sphuber committed Aug 31, 2023
1 parent 0879a4e commit 35c57b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions aiida/orm/utils/builders/code.py
Expand Up @@ -11,7 +11,6 @@
import enum
import pathlib

from aiida.cmdline.utils.decorators import with_dbenv
from aiida.common.utils import ErrorAccumulator
from aiida.common.warnings import warn_deprecation
from aiida.orm import InstalledCode, PortableCode
Expand Down Expand Up @@ -41,9 +40,13 @@ def validate(self, raise_error=True):
self._err_acc.run(self.validate_installed)
return self._err_acc.result(raise_error=self.CodeValidationError if raise_error else False)

@with_dbenv()
def new(self):
"""Build and return a new code instance (not stored)"""
from aiida.manage import get_manager

# Load the profile backend if not already the case.
get_manager().get_profile_storage()

self.validate()

# Will be used at the end to check if all keys are known (those that are not None)
Expand Down
5 changes: 3 additions & 2 deletions aiida/orm/utils/builders/computer.py
Expand Up @@ -8,7 +8,6 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Manage computer objects with lazy loading of the db env"""
from aiida.cmdline.utils.decorators import with_dbenv
from aiida.common.exceptions import ValidationError
from aiida.common.utils import ErrorAccumulator

Expand Down Expand Up @@ -62,11 +61,13 @@ def validate(self, raise_error=True):
"""Validate the computer options."""
return self._err_acc.result(raise_error=self.ComputerValidationError if raise_error else False)

@with_dbenv()
def new(self):
"""Build and return a new computer instance (not stored)"""
from aiida.manage import get_manager
from aiida.orm import Computer

# Load the profile backend if not already the case.
get_manager().get_profile_storage()
self.validate()

# Will be used at the end to check if all keys are known
Expand Down

0 comments on commit 35c57b9

Please sign in to comment.