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 and 20cents committed Aug 30, 2024
1 parent 63736d2 commit c2b0060
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 @@ -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":
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c2b0060

Please sign in to comment.