Skip to content

Commit

Permalink
ORM: Explicitly pass backend when constructing new entity
Browse files Browse the repository at this point in the history
Whenever an ORM entity instance instantiates another entry, it should
explicitly pass its own backend as the storage backend to use. Similarly,
functions that accept a storage backend as an argument, should
consistently pass whenever instantiating a new entity or its collection.

Co-Authored-By: Riccardo Bertossa <33728857+rikigigi@users.noreply.github.com>
  • Loading branch information
sphuber and rikigigi committed Sep 5, 2023
1 parent bac2152 commit 96667c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion aiida/orm/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def configure(self, user: Optional['User'] = None, **kwargs: Any) -> 'AuthInfo':
try:
authinfo = self.get_authinfo(user)
except exceptions.NotExistent:
authinfo = authinfos.AuthInfo(self, user)
authinfo = authinfos.AuthInfo(self, user, backend=self.backend)

auth_params = authinfo.get_auth_params()

Expand Down
2 changes: 1 addition & 1 deletion aiida/orm/nodes/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def add(self, content: str, user: t.Optional[User] = None) -> Comment:
:return: the newly created comment
"""
user = user or User.get_collection(self._node.backend).get_default()
return Comment(node=self._node, user=user, content=content).store()
return Comment(backend=self._node.backend, node=self._node, user=user, content=content).store()

def get(self, identifier: int) -> Comment:
"""Return a comment corresponding to the given identifier.
Expand Down
8 changes: 4 additions & 4 deletions aiida/orm/nodes/data/upf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def upload_upf_family(folder, group_label, group_description, stop_if_existing=T

if existing_upf is None:
# return the upfdata instances, not stored
pseudo, created = UpfData.get_or_create(filename, use_first=True, store_upf=False)
pseudo, created = UpfData.get_or_create(filename, use_first=True, store_upf=False, backend=backend)
# to check whether only one upf per element exists
# NOTE: actually, created has the meaning of "to_be_created"
pseudo_and_created.append((pseudo, created))
Expand Down Expand Up @@ -257,7 +257,7 @@ class UpfData(SinglefileData):
"""`Data` sub class to represent a pseudopotential single file in UPF format."""

@classmethod
def get_or_create(cls, filepath, use_first=False, store_upf=True):
def get_or_create(cls, filepath, use_first=False, store_upf=True, backend=None):
"""Get the `UpfData` with the same md5 of the given file, or create it if it does not yet exist.
:param filepath: an absolute filepath on disk
Expand All @@ -273,10 +273,10 @@ def get_or_create(cls, filepath, use_first=False, store_upf=True):
if not os.path.isabs(filepath):
raise ValueError('filepath must be an absolute path')

pseudos = cls.from_md5(md5_file(filepath))
pseudos = cls.from_md5(md5_file(filepath), backend=backend)

if not pseudos:
instance = cls(file=filepath)
instance = cls(file=filepath, backend=backend)
if store_upf:
instance.store()
return (instance, True)
Expand Down

0 comments on commit 96667c8

Please sign in to comment.