Skip to content

Commit

Permalink
Merge pull request #2766 from data-for-change/2765-add-data-consisten…
Browse files Browse the repository at this point in the history
…cy-to-fill_dictionary_tables

ensure data consistency, commit only after delete and insert, rollbac…
  • Loading branch information
atalyaalon authored Jan 21, 2025
2 parents 93c1d1d + 20dcd5b commit 264e7d5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions anyway/parsers/cbs/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ def fill_dictionary_tables(cbs_dictionary, provider_code, year):
+ str(inner_k)
)
db.session.execute(sql_delete)
db.session.commit()
sql_insert = (
"INSERT INTO "
+ curr_table
Expand All @@ -918,8 +917,12 @@ def fill_dictionary_tables(cbs_dictionary, provider_code, year):
+ " ON CONFLICT DO NOTHING"
)
db.session.execute(sql_insert)
db.session.commit()
logging.debug("Inserted/Updated dictionary values into table " + curr_table)
try:
db.session.commit()
except Exception as e:
logging.error(f"Error updating Dictionary tables: {e}")
db.session.rollback()
logging.debug("Inserted/Updated dictionary values into table " + curr_table)
create_provider_code_table()


Expand Down Expand Up @@ -951,7 +954,11 @@ def create_provider_code_table():
"INSERT INTO " + provider_code_table + " VALUES (" + str(k) + "," + "'" + v + "'" + ")"
)
db.session.execute(sql_insert)
try:
db.session.commit()
except Exception as e:
logging.error(f"Error updating table {provider_code_table}: {e}")
db.session.rollback()


def receive_rollback(conn, **kwargs):
Expand Down

0 comments on commit 264e7d5

Please sign in to comment.