Skip to content

Commit

Permalink
Move overwritting previous datasets values to after the copy was succ…
Browse files Browse the repository at this point in the history
…essful
  • Loading branch information
stuartmcalpine committed May 31, 2024
1 parent b54ba6e commit 12ce086
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/dataregistry/registrar/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,7 @@ def register(

# Create a new row in the data registry database.
with self._engine.connect() as conn:
prim_key = add_table_row(conn, dataset_table, values, commit=False)

if len(previous) > 0:
# Update previous rows, setting is_overwritten to True
update_stmt = (
update(dataset_table)
.where(dataset_table.c.dataset_id.in_(previous))
.values(is_overwritten=True)
)
conn.execute(update_stmt)
conn.commit()
prim_key = add_table_row(conn, dataset_table, values, commit=True)

# Get dataset characteristics; copy to `root_dir` if requested
if location_type == "dataregistry":
Expand All @@ -285,8 +275,9 @@ def register(
if creation_date:
ds_creation_date = creation_date

# Copy was successful, update the entry with dataset metadata
# Copy was successful
with self._engine.connect() as conn:
# Update the entry with dataset metadata
update_stmt = (
update(dataset_table)
.where(dataset_table.c.dataset_id == prim_key)
Expand All @@ -299,6 +290,16 @@ def register(
)
)
conn.execute(update_stmt)

# Update overwritten datasets `is_overwritten` values
if len(previous) > 0:
update_stmt = (
update(dataset_table)
.where(dataset_table.c.dataset_id.in_(previous))
.values(is_overwritten=True)
)
conn.execute(update_stmt)

conn.commit()

return prim_key, execution_id
Expand Down

0 comments on commit 12ce086

Please sign in to comment.