Skip to content

Commit

Permalink
Merge pull request #1133 from lsst/tickets/DM-48094
Browse files Browse the repository at this point in the history
DM-48094: Fix dataset fields not working in Butler.query_datasets
  • Loading branch information
dhirving authored Dec 12, 2024
2 parents 36ed777 + 3af7307 commit 8636101
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/DM-48094.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where dataset fields like `ingest_date` were raising `InvalidQueryError: Unrecognized identifier` when used in `Butler.query_datasets` `where` clause.
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 8636101

Please sign in to comment.