diff --git a/lib/rucio/core/did.py b/lib/rucio/core/did.py index b173cd98b2d..fbcda43d847 100644 --- a/lib/rucio/core/did.py +++ b/lib/rucio/core/did.py @@ -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 diff --git a/tests/test_did.py b/tests/test_did.py index b371baf27d8..0b5f9af6459 100644 --- a/tests/test_did.py +++ b/tests/test_did.py @@ -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):