Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-24018: fix bug in unrestricted queries over collections #243

Merged
merged 2 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions python/lsst/daf/butler/registry/interfaces/_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CollectionRecord(ABC):
def __init__(self, name: str, type: CollectionType):
self.name = name
self.type = type
assert isinstance(self.type, CollectionType)

@property
@abstractmethod
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def testCollections(self):
self.assertIs(registry.getCollectionType(chain1), CollectionType.CHAINED)
# Chained collection exists, but has no collections in it.
self.assertFalse(registry.getCollectionChain(chain1))
# If we query for all collections, we should get the chained collection
# only if we don't ask to flatten it (i.e. yield only its children).
self.assertEqual(set(registry.queryCollections(flattenChains=False)), {tag1, run1, run2, chain1})
self.assertEqual(set(registry.queryCollections(flattenChains=True)), {tag1, run1, run2})
# Attempt to set its child collections to something circular; that
# should fail.
with self.assertRaises(ValueError):
Expand Down
14 changes: 13 additions & 1 deletion python/lsst/daf/butler/registry/wildcards.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ def _yieldCollectionRecords(
The given dataset type restriction; yielded only if
``withRestrictions`` is `True`.
"""
if done is None:
done = set()
includeChains = includeChains if includeChains is not None else not flattenChains
if collectionType is None or record.type is collectionType:
done.add(record.name)
Expand Down Expand Up @@ -722,7 +724,17 @@ def iter(
their children, but not both.
"""
if self._search is ...:
yield from manager
for record in manager:
yield from _yieldCollectionRecords(
manager,
record,
DatasetTypeRestriction.any,
datasetType=datasetType,
collectionType=collectionType,
withRestrictions=withRestrictions,
flattenChains=flattenChains,
includeChains=includeChains,
)
else:
done = set()
yield from self._search.iter(
Expand Down