From c2b0060f636d4da5b381ea93c65a99b64bc49b13 Mon Sep 17 00:00:00 2001 From: Jules Grillot <37152611+JulesGrillot@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:30:14 +0200 Subject: [PATCH] Update forms.py Correct forms 4, 6 and 7 error when updating zh Modify select for delete. The old element needs to be deleted before inserting the new one, else a unique constraint might be broken. --- backend/gn_module_zh/forms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/gn_module_zh/forms.py b/backend/gn_module_zh/forms.py index 41020485..c2fed700 100644 --- a/backend/gn_module_zh/forms.py +++ b/backend/gn_module_zh/forms.py @@ -607,7 +607,7 @@ def post_outflow(id_zh, outflows): def update_inflow(id_zh, inflows): try: - DB.session.execute(select(TInflow).where(TInflow.id_zh == id_zh)) + DB.session.execute(delete(TInflow).where(TInflow.id_zh == id_zh)) post_inflow(id_zh, inflows) except Exception as e: if e.__class__.__name__ == "DataError": @@ -823,7 +823,7 @@ def post_instruments(id_zh, instruments): def update_protections(id_zh, protections): try: - DB.session.execute(select(CorZhProtection).where(CorZhProtection.id_zh == id_zh)) + DB.session.execute(delete(CorZhProtection).where(CorZhProtection.id_zh == id_zh)) post_protections(id_zh, protections) except Exception as e: if e.__class__.__name__ == "DataError": @@ -931,7 +931,7 @@ def post_urban_docs(id_zh, urban_docs): def update_actions(id_zh, actions): try: # delete cascade actions - DB.session.execute(select(TActions).where(TActions.id_zh == id_zh)) + DB.session.execute(delete(TActions).where(TActions.id_zh == id_zh)) # post new actions post_actions(id_zh, actions) except Exception as e: