diff --git a/python/lsst/daf/butler/registry/datasets/byDimensions/_manager.py b/python/lsst/daf/butler/registry/datasets/byDimensions/_manager.py index 288c452fbe..e9a6a891bb 100644 --- a/python/lsst/daf/butler/registry/datasets/byDimensions/_manager.py +++ b/python/lsst/daf/butler/registry/datasets/byDimensions/_manager.py @@ -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: diff --git a/python/lsst/daf/butler/registry/tests/_registry.py b/python/lsst/daf/butler/registry/tests/_registry.py index 4b6334fb18..439414a6a3 100644 --- a/python/lsst/daf/butler/registry/tests/_registry.py +++ b/python/lsst/daf/butler/registry/tests/_registry.py @@ -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`.