Skip to content

Commit

Permalink
Fail dataset type query early on non extant type
Browse files Browse the repository at this point in the history
If a dataset type is used in queryDatasetTypes call, and it is a
type that is not known to the registry, the method should raise
instead of silently continuing. This was causing down stream
consumers of this method to get confusing registry issues.
  • Loading branch information
natelust committed Nov 3, 2021
1 parent ca54b62 commit f04e8f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
14 changes: 11 additions & 3 deletions python/lsst/daf/butler/registries/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
CollectionSearch,
)
from ..registry import queries

from ..registry.wildcards import CategorizedWildcard, CollectionQuery, Ellipsis
from ..registry.summaries import CollectionSummary
from ..registry.managers import RegistryManagerTypes, RegistryManagerInstances
Expand Down Expand Up @@ -736,9 +737,16 @@ def queryDatasetTypes(self, expression: Any = ..., *, components: Optional[bool]
done: Set[str] = set()
for name in wildcard.strings:
storage = self._managers.datasets.find(name)
if storage is not None:
done.add(storage.datasetType.name)
yield storage.datasetType
if storage is None:
raise ValueError(f"queryDatasetTypes was constrained with dataset type {name}, but no type"
"with that name has been declared to the registry. Please register the"
"dataset type and try again. Of note, if the registry is being used"
"in a parallel manner, it is possible the type has been registered "
"elsewhere, and the cache is out of date now, recreating the registry"
"instance, or calling the refresh method will update the registry to be"
"consistent with the other registry instances.")
done.add(storage.datasetType.name)
yield storage.datasetType
if wildcard.patterns:
# If components (the argument) is None, we'll save component
# dataset that we might want to match, but only if their parents
Expand Down
20 changes: 2 additions & 18 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
MissingCollectionError,
OrphanedRecordError,
)


from ..interfaces import ButlerAttributeExistsError

if TYPE_CHECKING:
Expand Down Expand Up @@ -2376,24 +2378,6 @@ def testQueryResultSummaries(self):
# These queries yield no results due to various problems that can be
# spotted prior to execution, yielding helpful diagnostics.
for query, snippets in [
(
# Dataset type name doesn't match any existing dataset types.
registry.queryDatasets("nonexistent", collections=...),
["nonexistent"],
),
(
# Dataset type object isn't registered.
registry.queryDatasets(
DatasetType(
"nonexistent",
dimensions=["instrument"],
universe=registry.dimensions,
storageClass="Image",
),
collections=...
),
["nonexistent"],
),
(
# No datasets of this type in this collection.
registry.queryDatasets("flat", collections=["biases"]),
Expand Down

0 comments on commit f04e8f6

Please sign in to comment.