Skip to content

Commit 510755a

Browse files
Fix from_serialized
1 parent cc7ff80 commit 510755a

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

src/aiida/orm/entities.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,10 @@ def serialize(
376376
).model_dump(mode=mode)
377377

378378
@classmethod
379-
def from_serialized(cls, unstored: bool = False, **kwargs: dict[str, Any]) -> Self:
379+
def from_serialized(cls, serialized: dict[str, Any], unstored: bool = False) -> Self:
380380
"""Construct an entity instance from JSON serialized data.
381381
382+
:param serialized: A dictionary representing the serialized entity.
382383
:param unstored: If True, the input version of the model is used, which strips read-only fields, i.e., fields
383384
with `exclude_to_orm=True`.
384385
:return: An instance of the entity class.
@@ -387,7 +388,7 @@ def from_serialized(cls, unstored: bool = False, **kwargs: dict[str, Any]) -> Se
387388
'Serialization through pydantic is still an experimental feature and might break in future releases.'
388389
)
389390
Model = cls.InputModel if unstored else cls.Model # noqa: N806
390-
return cls.from_model(Model(**kwargs))
391+
return cls.from_model(Model(**serialized))
391392

392393
@classproperty
393394
def objects(cls: EntityType) -> CollectionType: # noqa: N805

tests/orm/data/code/test_abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ def test_serialization():
7272
label = 'some-label'
7373
code = MockCode(label=label)
7474

75-
MockCode.from_serialized(unstored=True, **code.serialize(unstored=True))
75+
MockCode.from_serialized(code.serialize(unstored=True), unstored=True)

tests/orm/data/code/test_installed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,4 @@ def test_serialization(aiida_localhost, bash_path):
152152
"""Test the deprecated :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.get_execname` method."""
153153
code = InstalledCode(label='some-label', computer=aiida_localhost, filepath_executable=str(bash_path.absolute()))
154154

155-
InstalledCode.from_serialized(unstored=True, **code.serialize(unstored=True))
155+
InstalledCode.from_serialized(code.serialize(unstored=True), unstored=True)

tests/orm/data/code/test_portable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,4 @@ def test_serialization(tmp_path, chdir_tmp_path):
176176
(filepath_files / 'subdir').mkdir()
177177
(filepath_files / 'subdir/test').write_text('test')
178178
code = PortableCode(label='some-label', filepath_executable='bash', filepath_files=filepath_files)
179-
PortableCode.from_serialized(unstored=True, **code.serialize(unstored=True))
179+
PortableCode.from_serialized(code.serialize(unstored=True), unstored=True)

tests/orm/models/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ def test_roundtrip_serialization(required_arguments, tmp_path):
214214

215215
# Get the model instance from the entity instance
216216
serialized_entity = entity.serialize(repository_path=tmp_path, unstored=True, mode='python')
217-
entity.from_serialized(unstored=True, **serialized_entity)
217+
entity.from_serialized(serialized_entity, unstored=True)

0 commit comments

Comments
 (0)