Skip to content

Commit

Permalink
fix little issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jan 22, 2025
1 parent 19b2ccf commit a55e0cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ def _apply(self, study_data: FileStudy, listener: t.Optional[ICommandListener] =
if not old_parameters:
db_properties = LinkTsGeneration.model_validate(db_properties_json)
new_parameters = db_properties.to_db_model(study_id, area_from, area_to)
db.session.add(new_parameters)
db.session.commit()
else:
old_props = LinkTsGeneration.from_db_model(old_parameters).model_dump(mode="json")
old_props.update(db_properties_json)
Expand All @@ -90,10 +88,9 @@ def _apply(self, study_data: FileStudy, listener: t.Optional[ICommandListener] =
# We should keep the same matrices
new_parameters.modulation = old_parameters.modulation
new_parameters.project = old_parameters.prepro
# todo: I should do it more efficiently but a merge creates 2 entry ...
db.session.delete(old_parameters)
db.session.add(new_parameters)
db.session.commit()
db.session.add(new_parameters)
db.session.commit()

# Updates matrices
if self.series:
Expand Down
11 changes: 3 additions & 8 deletions tests/variantstudy/model/command/test_update_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
#
# This file is part of the Antares project.

from antarest.core.utils.fastapi_sqlalchemy import db
from antarest.study.model import LinksParametersTsGeneration, RawStudy
from antarest.study.storage.rawstudy.ini_reader import IniReader
from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy
from antarest.study.storage.variantstudy.model.command.create_area import CreateArea
from antarest.study.storage.variantstudy.model.command.create_link import CreateLink
from antarest.study.storage.variantstudy.model.command.update_link import UpdateLink
from antarest.study.storage.variantstudy.model.command_context import CommandContext
from core.utils.fastapi_sqlalchemy import db
from db_statement_recorder import DBStatementRecorder
from study.storage.variantstudy.model.command.update_link import UpdateLink
from tests.db_statement_recorder import DBStatementRecorder
from tests.helpers import with_db_context


Expand Down Expand Up @@ -93,11 +93,6 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext):
# Removes the ini file to show we don't need it as we're only updating the DB
ini_path.unlink()

with DBStatementRecorder(db.session.bind) as db_recorder:
UpdateLink.model_validate(update_parameters).apply(study_data=empty_study)
# todo: this check seems random, don't know why :/
# assert len(db_recorder.sql_statements) == 3

# Checks the DB state. Old properties should remain the same and the new one should be updated
ts_gen_properties = (
db.session.query(LinksParametersTsGeneration)
Expand Down

0 comments on commit a55e0cf

Please sign in to comment.