Skip to content

Commit

Permalink
Update forms.py
Browse files Browse the repository at this point in the history

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.
  • Loading branch information
JulesGrillot authored Aug 23, 2024
1 parent 3ffb8d1 commit fb607fe
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/gn_module_zh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,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":
Expand Down Expand Up @@ -820,7 +820,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":
Expand Down Expand Up @@ -928,7 +928,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:
Expand Down

0 comments on commit fb607fe

Please sign in to comment.