diff --git a/antarest/study/storage/variantstudy/model/command/update_link.py b/antarest/study/storage/variantstudy/model/command/update_link.py index 7069154091..26c3e0735e 100644 --- a/antarest/study/storage/variantstudy/model/command/update_link.py +++ b/antarest/study/storage/variantstudy/model/command/update_link.py @@ -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) @@ -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: diff --git a/tests/variantstudy/model/command/test_update_link.py b/tests/variantstudy/model/command/test_update_link.py index f2ff4bc8a9..6935bd0a2f 100644 --- a/tests/variantstudy/model/command/test_update_link.py +++ b/tests/variantstudy/model/command/test_update_link.py @@ -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 @@ -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)