Skip to content

Commit

Permalink
Core & Internals: handle missing did in list_content. Closes rucio#6231.
Browse files Browse the repository at this point in the history
  • Loading branch information
Radu Carpa committed Nov 13, 2023
1 parent 4380d02 commit e3a951c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/rucio/core/did.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,20 +1655,22 @@ def list_content(scope, name, *, session: "Session"):
:param name: The data identifier name.
:param session: The database session in use.
"""
try:
stmt = select(
models.DataIdentifierAssociation
).with_hint(
models.DataIdentifierAssociation, "INDEX(CONTENTS CONTENTS_PK)", 'oracle'
).filter_by(
scope=scope,
name=name
)
for tmp_did in session.execute(stmt).yield_per(5).scalars():
yield {'scope': tmp_did.child_scope, 'name': tmp_did.child_name, 'type': tmp_did.child_type,
'bytes': tmp_did.bytes, 'adler32': tmp_did.adler32, 'md5': tmp_did.md5}
except NoResultFound:
raise exception.DataIdentifierNotFound(f"Data identifier '{scope}:{name}' not found")
stmt = select(
models.DataIdentifierAssociation
).with_hint(
models.DataIdentifierAssociation, "INDEX(CONTENTS CONTENTS_PK)", 'oracle'
).filter_by(
scope=scope,
name=name
)
children_found = False
for tmp_did in session.execute(stmt).yield_per(5).scalars():
children_found = True
yield {'scope': tmp_did.child_scope, 'name': tmp_did.child_name, 'type': tmp_did.child_type,
'bytes': tmp_did.bytes, 'adler32': tmp_did.adler32, 'md5': tmp_did.md5}
if not children_found:
# Raise exception if the did doesn't exist
__get_did(scope=scope, name=name, session=session)


@stream_session
Expand Down
3 changes: 3 additions & 0 deletions tests/test_did.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,9 @@ def test_list_content(self, did_client, rse_factory):
files1 = [{'scope': scope, 'name': did_name_generator('file'), 'bytes': 1, 'adler32': '0cc737eb'} for i in range(nbfiles)]
files2 = [{'scope': scope, 'name': did_name_generator('file'), 'bytes': 1, 'adler32': '0cc737eb'} for i in range(nbfiles)]

with pytest.raises(DataIdentifierNotFound):
did_client.list_content(scope, dataset1)

did_client.add_dataset(scope, dataset1)

with pytest.raises(DataIdentifierAlreadyExists):
Expand Down

0 comments on commit e3a951c

Please sign in to comment.