Skip to content

Commit

Permalink
Fix failed assertion after cache miss
Browse files Browse the repository at this point in the history
Fix a bug where loading a dataset type registered externally after the Butler had loaded a "full" dataset type cache would cause an assertion failure "Dataset type cache population is incomplete" due to only filling in one of the two caches.
  • Loading branch information
dhirving committed Dec 10, 2024
1 parent efa3711 commit 3c649f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ def _find_storage(self, name: str) -> _DatasetRecordStorage:
record = self._fetch_dataset_type_record(name)
if record is not None:
self._cache.add(record.dataset_type, record.dataset_type_id)
return _DatasetRecordStorage(
record.dataset_type, record.dataset_type_id, record.make_dynamic_tables()
)
tables = record.make_dynamic_tables()
self._cache.add_by_dimensions(record.dataset_type.dimensions, tables)
return _DatasetRecordStorage(record.dataset_type, record.dataset_type_id, tables)
raise MissingDatasetTypeError(f"Dataset type {name!r} does not exist.")

def getCollectionSummary(self, collection: CollectionRecord) -> CollectionSummary:
Expand Down
22 changes: 22 additions & 0 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ def testDatasetType(self):
self.assertCountEqual([dt.name for dt in types], ["test", "testNoneTemplate"])
self.assertEqual(missing, ["notarealdatasettype"])

def testDatasetTypeCache(self):
"""Test for dataset type cache update logic after a cache miss."""
butler1 = self.make_butler()
butler2 = butler1.clone()
self.load_data(butler1, "base.yaml")

# Trigger full cache load.
butler2.get_dataset_type("flat")
# Have an external process register a dataset type.
butler1.registry.registerDatasetType(
DatasetType("test_type", ["instrument"], "int", universe=butler1.dimensions)
)
# Try to read the new dataset type -- this is a cache miss that
# triggers fetch of a single dataset type.
dt = butler2.get_dataset_type("test_type")
self.assertEqual(dt.name, "test_type")
self.assertEqual(list(dt.dimensions.names), ["instrument"])
# Use the dataset type's tags table.
self.assertEqual(
butler2.query_datasets("test_type", collections="*", find_first=False, explain=False), []
)

def testDimensions(self):
"""Tests for `SqlRegistry.insertDimensionData`,
`SqlRegistry.syncDimensionData`, and `SqlRegistry.expandDataId`.
Expand Down

0 comments on commit 3c649f7

Please sign in to comment.