From 6ad71ba5591f56d44b242a6208e09a0cb0a6688a Mon Sep 17 00:00:00 2001 From: "David H. Irving" Date: Fri, 1 Nov 2024 13:53:13 -0700 Subject: [PATCH] Fix dataset query missing implied dimensions Revert serialization changes from DM-46776 in SerializedDatasetType and SerializedDataCoordinate, which caused them to drop implied dimensions. This leads to an incorrect definition of the dataset type after deserialization, since it is missing some dimensions. It also breaks the transfer of DatasetRefs from server to client, since it drops the values for implied dimensions in the data ID. Per the documented behavior of dataset queries, the returned refs will have `hasFull() = True` and this behavior is relied on in tutorial notebooks. --- python/lsst/daf/butler/_dataset_type.py | 2 +- python/lsst/daf/butler/dimensions/_coordinate.py | 2 +- python/lsst/daf/butler/tests/butler_queries.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/lsst/daf/butler/_dataset_type.py b/python/lsst/daf/butler/_dataset_type.py index e9ba515ef9..c7b546cc94 100644 --- a/python/lsst/daf/butler/_dataset_type.py +++ b/python/lsst/daf/butler/_dataset_type.py @@ -676,7 +676,7 @@ def to_simple(self, minimal: bool = False) -> SerializedDatasetType: "name": self.name, "storageClass": self._storageClassName, "isCalibration": self._isCalibration, - "dimensions": list(self._dimensions.required), + "dimensions": list(self._dimensions.names), } if self._parentStorageClassName is not None: diff --git a/python/lsst/daf/butler/dimensions/_coordinate.py b/python/lsst/daf/butler/dimensions/_coordinate.py index d511a49cac..d6f4189e9c 100644 --- a/python/lsst/daf/butler/dimensions/_coordinate.py +++ b/python/lsst/daf/butler/dimensions/_coordinate.py @@ -709,7 +709,7 @@ def to_simple(self, minimal: bool = False) -> SerializedDataCoordinate: else: records = None - return SerializedDataCoordinate(dataId=dict(self.required), records=records) + return SerializedDataCoordinate(dataId=dict(self.mapping), records=records) @classmethod def from_simple( diff --git a/python/lsst/daf/butler/tests/butler_queries.py b/python/lsst/daf/butler/tests/butler_queries.py index 0410afcef5..64aaa1bbb8 100644 --- a/python/lsst/daf/butler/tests/butler_queries.py +++ b/python/lsst/daf/butler/tests/butler_queries.py @@ -303,6 +303,18 @@ def test_simple_dataset_query(self) -> None: butler.query_datasets("bias", "*", detector=100, instrument="Unknown", find_first=False) self.assertIn("doomed", str(cm2.exception)) + # Test for a regression of an issue where "band" was not being included + # in the data ID, despite being one of the dimensions in the "flat" + # dataset type. + refs = butler.query_datasets("flat", "imported_r", where="detector = 2", instrument="Cam1") + self.assertEqual(len(refs), 1) + flat = refs[0] + self.assertEqual(flat.datasetType.name, "flat") + self.assertEqual(flat.dataId["instrument"], "Cam1") + self.assertEqual(flat.dataId["detector"], 2) + self.assertEqual(flat.dataId["physical_filter"], "Cam1-R1") + self.assertEqual(flat.dataId["band"], "r") + def test_general_query(self) -> None: """Test Query.general and its result.""" butler = self.make_butler("base.yaml", "datasets.yaml")