Skip to content

Commit

Permalink
Fix dataset fields not working in Butler.query_datasets
Browse files Browse the repository at this point in the history
Fix an issue where dataset fields like `ingest_date` were raising `InvalidQueryError: Unrecognized identifier` because the where clause was being applied before query was known to be a dataset query.
  • Loading branch information
dhirving committed Dec 11, 2024
1 parent f14086a commit da570e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/_butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,8 +1869,8 @@ def query_datasets(
warn_limit = True
with self.query() as query:
result = (
query.where(data_id, where, bind=bind, **kwargs)
.datasets(dataset_type, collections=collections, find_first=find_first)
query.datasets(dataset_type, collections=collections, find_first=find_first)
.where(data_id, where, bind=bind, **kwargs)
.order_by(*ensure_iterable(order_by))
.limit(query_limit)
)
Expand Down
7 changes: 7 additions & 0 deletions python/lsst/daf/butler/tests/butler_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,13 @@ def test_dataset_queries(self) -> None:
self.assertEqual(rows[0]["visit"], 1)
self.assertEqual(rows[0]["dt.collection"], "run1")

# Test that dataset fields like ingest_date can be used in the 'where'
# clause.
result = butler.query_datasets("dt", "run1", where="ingest_date > T'2000-01-01'")
self.assertEqual(len(result), 1)
result = butler.query_datasets("dt", "run1", where="ingest_date < T'2000-01-01'", explain=False)
self.assertEqual(len(result), 0)

def test_multiple_instrument_queries(self) -> None:
"""Test that multiple-instrument queries are not rejected as having
governor dimension ambiguities.
Expand Down

0 comments on commit da570e7

Please sign in to comment.