Skip to content

Commit 1b613b0

Browse files
thodson-usgsclaude
andcommitted
Fix get_reference_table: propagate limit to query args
The signature accepted and documented a `limit` parameter, but the function never forwarded it into `query_args`, so every call fetched at the schema/server default regardless of what the user requested. Forward `limit` into a copy of the user-supplied `query` dict (so the caller's dict is not mutated) when it is not None. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 51ac674 commit 1b613b0

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

dataretrieval/waterdata/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,9 @@ def get_reference_table(
15421542
else:
15431543
output_id = f"{collection.replace('-', '_')}"
15441544

1545-
query_args = query or {}
1545+
query_args = dict(query) if query else {}
1546+
if limit is not None:
1547+
query_args["limit"] = limit
15461548
return get_ogc_data(args=query_args, output_id=output_id, service=collection)
15471549

15481550

tests/waterdata_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,33 @@ def test_get_reference_table_wrong_name():
322322
get_reference_table("agency-cod")
323323

324324

325+
def test_get_reference_table_propagates_limit(requests_mock):
326+
"""The `limit` argument must reach the OGC `limit` query parameter."""
327+
request_url = (
328+
"https://api.waterdata.usgs.gov/ogcapi/v0/collections/agency-codes/items"
329+
)
330+
body = {
331+
"type": "FeatureCollection",
332+
"features": [
333+
{
334+
"type": "Feature",
335+
"id": "USGS",
336+
"properties": {"agency_code": "USGS"},
337+
"geometry": None,
338+
}
339+
],
340+
"numberReturned": 1,
341+
"links": [],
342+
}
343+
requests_mock.get(request_url, json=body, headers={"mock_header": "value"})
344+
345+
df, _md = get_reference_table("agency-codes", limit=42)
346+
347+
sent = requests_mock.request_history[-1]
348+
assert sent.qs.get("limit") == ["42"]
349+
assert "agency_code" in df.columns
350+
351+
325352
def test_get_stats_por():
326353
df, _ = get_stats_por(
327354
monitoring_location_id="USGS-12451000",

0 commit comments

Comments
 (0)