Skip to content

Commit

Permalink
Merge pull request #130 from LSSTDESC/u/stuart/reorder_overwrite
Browse files Browse the repository at this point in the history
Reorder overwritten
  • Loading branch information
stuartmcalpine committed Jun 4, 2024
2 parents cad7dcd + 061bae6 commit deda722
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version 0.5.2

When registering a dataset that is overwriting a previous dataset, don't tag
the previous datasets as `valid=False` until any data copying is successful.

## Version 0.5.1

Add ability to tag datasets with keywords/labels to make them easier to
Expand Down
2 changes: 1 addition & 1 deletion src/dataregistry/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.1"
__version__ = "0.5.2"
27 changes: 12 additions & 15 deletions src/dataregistry/registrar/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,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)

# Update the rows of the overwritten dataset
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()
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 @@ -287,20 +276,19 @@ def register(
) = self._handle_data(
relative_path, old_location, owner, owner_type, verbose
)
valid_status = 1
else:
dataset_organization = location_type
num_files = 0
total_size = 0
ds_creation_date = None
valid_status = 0

# Case where user is overwriting the dataset `creation_date`
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 @@ -314,6 +302,15 @@ 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)

# Add any keyword tags
if len(keywords) > 0:
keyword_table = self._get_table_metadata("dataset_keyword")
Expand Down

0 comments on commit deda722

Please sign in to comment.