Skip to content

Commit

Permalink
fix(variants): correct the generation of variant when a snapshot is r…
Browse files Browse the repository at this point in the history
…emoved (#1947)
  • Loading branch information
laurent-laporte-pro authored and skamril committed Feb 27, 2024
1 parent 5dd2711 commit 20a332a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ class Study(Base): # type: ignore
__mapper_args__ = {"polymorphic_identity": "study", "polymorphic_on": type}

def __str__(self) -> str:
cls = self.__class__.__name__
return (
f"[Study]"
f"[{cls}]"
f" id={self.id},"
f" type={self.type},"
f" name={self.name},"
Expand Down
4 changes: 4 additions & 0 deletions antarest/study/storage/variantstudy/model/dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ def is_snapshot_up_to_date(self) -> bool:
and (self.snapshot.created_at >= self.updated_at)
and (self.snapshot_dir / "study.antares").is_file()
)

def has_snapshot(self) -> bool:
"""Check if the snapshot exists."""
return (self.snapshot is not None) and (self.snapshot_dir / "study.antares").is_file()
2 changes: 1 addition & 1 deletion antarest/study/storage/variantstudy/snapshot_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def search_ref_study(
# To reuse the snapshot of the current variant, the last executed command
# must be one of the commands of the current variant.
curr_variant = descendants[-1]
if curr_variant.snapshot:
if curr_variant.has_snapshot():
last_exec_cmd = curr_variant.snapshot.last_executed_command
command_ids = [c.id for c in curr_variant.commands]
# If the variant has no command, we can reuse the snapshot if it is recent
Expand Down
2 changes: 1 addition & 1 deletion tests/study/storage/variantstudy/model/test_dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_init__without_snapshot(self, db_session: Session, raw_study_id: str, us
obj: VariantStudy = db_session.query(VariantStudy).filter(VariantStudy.id == variant_study_id).one()

# check Study representation
assert str(obj).startswith(f"[Study] id={variant_study_id}")
assert str(obj).startswith(f"[VariantStudy] id={variant_study_id}")

# check Study fields
assert obj.id == variant_study_id
Expand Down

0 comments on commit 20a332a

Please sign in to comment.