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-33772: Clean up the components warning in queryDatasetTypes #650

Merged
merged 3 commits into from
Feb 24, 2022
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
23 changes: 12 additions & 11 deletions python/lsst/daf/butler/registries/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ def queryDatasetTypes(
) -> Iterator[DatasetType]:
# Docstring inherited from lsst.daf.butler.registry.Registry
wildcard = CategorizedWildcard.fromExpression(expression, coerceUnrecognized=lambda d: d.name)
unknownComponentsMessage = (
"Could not find definition for storage class %s for dataset type %r;"
" if it has components they will not be included in dataset type query results."
)
if wildcard is Ellipsis:
for datasetType in self._managers.datasets:
# The dataset type can no longer be a component
Expand All @@ -794,10 +798,7 @@ def queryDatasetTypes(
try:
componentsForDatasetType = datasetType.makeAllComponentDatasetTypes()
except KeyError as err:
_LOG.warning(
f"Could not load storage class {err} for {datasetType.name}; "
"if it has components they will not be included in query results."
)
_LOG.warning(unknownComponentsMessage, err, datasetType.name)
else:
yield from componentsForDatasetType
return
Expand All @@ -818,13 +819,13 @@ def queryDatasetTypes(
for registeredDatasetType in self._managers.datasets:
# Components are not stored in registry so expand them here
allDatasetTypes = [registeredDatasetType]
try:
allDatasetTypes.extend(registeredDatasetType.makeAllComponentDatasetTypes())
except KeyError as err:
_LOG.warning(
f"Could not load storage class {err} for {registeredDatasetType.name}; "
"if it has components they will not be included in query results."
)
if components is not False:
# Only check for the components if we are being asked
# for components or components is None.
try:
allDatasetTypes.extend(registeredDatasetType.makeAllComponentDatasetTypes())
except KeyError as err:
_LOG.warning(unknownComponentsMessage, err, registeredDatasetType.name)
for datasetType in allDatasetTypes:
if datasetType.name in done:
continue
Expand Down
7 changes: 7 additions & 0 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ def testDatasetTypeComponentQueries(self):
startsWithTemp = NamedValueSet(registry.queryDatasetTypes(re.compile("temp.*")))
self.assertIn("TempStorageClass", cm.output[0])
self.assertEqual({"temporary"}, startsWithTemp.names)
# Querying with no components should not warn at all.
with self.assertLogs("lsst.daf.butler.registries", logging.WARN) as cm:
startsWithTemp = NamedValueSet(registry.queryDatasetTypes(re.compile("temp.*"), components=False))
# Must issue a warning of our own to be captured.
logging.getLogger("lsst.daf.butler.registries").warning("test message")
self.assertEqual(len(cm.output), 1)
self.assertIn("test message", cm.output[0])

def testComponentLookups(self):
"""Test searching for component datasets via their parents."""
Expand Down
22 changes: 12 additions & 10 deletions tests/test_cliCmdPruneCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,25 @@ def testPruneCollections(self):
self.assertIn(taggedName, result.output)

# Verify the tagged collection can be removed:
result = self.runner.invoke(
butlerCli,
["prune-collection", repoName, taggedName, "--unstore"],
input="yes",
)
with self.assertWarns(FutureWarning): # Capture the deprecation warning
result = self.runner.invoke(
butlerCli,
["prune-collection", repoName, taggedName, "--unstore"],
input="yes",
)
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
result = self.runner.invoke(butlerCli, ["query-collections", repoName])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
self.assertIn(runName, result.output)
self.assertNotIn(taggedName, result.output)

# Verify the run can be removed:
result = self.runner.invoke(
butlerCli,
["prune-collection", repoName, runName, "--purge", "--unstore"],
input="yes",
)
with self.assertWarns(FutureWarning): # Capture the deprecation warning
result = self.runner.invoke(
butlerCli,
["prune-collection", repoName, runName, "--purge", "--unstore"],
input="yes",
)
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
result = self.runner.invoke(butlerCli, ["query-collections", repoName])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))
Expand Down