Skip to content

Commit

Permalink
Add method to replace DatasetRef data ID with expanded one.
Browse files Browse the repository at this point in the history
We need this to fix previous loophole usage in queryDatasets.
  • Loading branch information
TallJimbo committed Dec 5, 2019
1 parent 4619ccd commit c48e0ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 20 additions & 1 deletion python/lsst/daf/butler/core/datasets/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from typing import Any, Dict, Mapping, Optional, Tuple

from types import MappingProxyType
from ..dimensions import DataCoordinate, DimensionGraph
from ..dimensions import DataCoordinate, DimensionGraph, ExpandedDataCoordinate
from ..run import Run
from ..configSupport import LookupKey
from ..utils import immutable
Expand Down Expand Up @@ -183,6 +183,25 @@ def unresolved(self) -> DatasetRef:
"""
return DatasetRef(datasetType=self.datasetType, dataId=self.dataId, hash=self.hash, conform=False)

def expanded(self, dataId: ExpandedDataCoordinate) -> DatasetRef:
"""Return a new `DatasetRef` with the given expanded data ID.
Parameters
----------
dataId : `ExpandedDataCoordinate`
Data ID for the new `DatasetRef`. Must compare equal to the
original data ID.
Returns
-------
ref : `DatasetRef`
A new `DatasetRef` with the given data ID.
"""
assert dataId == self.dataId
return DatasetRef(datasetType=self.datasetType, dataId=dataId,
id=self.id, run=self.run, hash=self.hash, components=self.components,
conform=False)

def isComponent(self) -> bool:
"""Boolean indicating whether this `DatasetRef` refers to a
component of a composite.
Expand Down
3 changes: 1 addition & 2 deletions python/lsst/daf/butler/registries/sqlRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,7 @@ def queryDatasets(self, datasetType: DatasetTypeExpression, *,
if expand:
for ref in bestRefs.values():
dataId = self.expandDataId(ref.dataId, records=standardizedDataId.records)
ref._dataId = dataId # TODO: add semi-public API for this?
yield ref
yield ref.expanded(dataId)
else:
yield from bestRefs.values()

Expand Down

0 comments on commit c48e0ea

Please sign in to comment.