Skip to content

Commit

Permalink
Fixed bug where split filelists would not be added to the same holding
Browse files Browse the repository at this point in the history
  • Loading branch information
nmassey001 committed Jan 8, 2025
1 parent 172dbae commit 593cc6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
21 changes: 13 additions & 8 deletions nlds_processors/catalog/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,29 @@ def get_holding(
Holding.user == user,
)

# Note - the order of these if.elif.elif statements is very important - do
# not change the order!
# holding id filtering - for when the user supplies a holding id
if holding_id:
holding_q = holding_q.filter(
Holding.id == holding_id,
)

if transaction_id:
holding_q = holding_q.filter(
Transaction.holding_id == Holding.id,
Transaction.transaction_id == transaction_id,
)

# search label filtering
if label:
# search label filtering - for when the user supplies a holding label
elif label:
if is_regex(label):
holding_q = holding_q.filter(Holding.label.regexp_match(label))
else:
holding_q = holding_q.filter(Holding.label == label)

# transaction id filtering - for when a large upload has been split into
# multiple uploads
elif transaction_id:
holding_q = holding_q.filter(
Transaction.holding_id == Holding.id,
Transaction.transaction_id == transaction_id,
)

# filter the query on any tags
if tag:
# get the holdings that have a key that matches one or more of
Expand Down
17 changes: 12 additions & 5 deletions nlds_processors/catalog/catalog_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,20 @@ def _get_search_label(self, holding_label, holding_id):
# this will produce a new holding
return search_label

def _get_or_create_holding(self, user, group, label, holding_id, new_label):
"""Get a holding via label or holding_id.
def _get_or_create_holding(
self, user, group, search_label, holding_id, transaction_id, new_label
):
"""Get a holding via label or holding_id or transaction_id.
If the holding doesn't already exist then create it."""
# try to get the holding to see if it already exists and can be added to
try:
# don't use tags to search - they are strictly for adding to the holding
holding = self.catalog.get_holding(
user, group, label=label, holding_id=holding_id
user,
group,
label=search_label,
holding_id=holding_id,
transaction_id=transaction_id,
)
except (KeyError, CatalogError):
holding = None
Expand Down Expand Up @@ -434,8 +440,9 @@ def _catalog_put(self, body: Dict, rk_origin: str) -> None:
holding = self._get_or_create_holding(
user,
group,
label=search_label,
search_label=search_label,
holding_id=holding_id,
transaction_id=transaction_id,
new_label=new_label,
)
except CatalogError as e:
Expand Down Expand Up @@ -733,7 +740,7 @@ def _catalog_get(self, body: Dict, rk_origin: str) -> None:
else:
access_time = datetime.fromtimestamp(pl.access_time)

# create a mostly empty OBJECT STORAGE location in the database
# create a mostly empty OBJECT STORAGE location in the database
# as a marker that the file is currently transferring
self.catalog.create_location(
file_=file,
Expand Down

0 comments on commit 593cc6a

Please sign in to comment.