Skip to content

fix(ogc): raise on an unreadable date bound instead of dropping the filter - #441

Merged
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/raise-on-unparseable-date-bound
Oct 8, 2026
Merged

thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/raise-on-unparseable-date-bound

Conversation

@thodson-usgs

@thodson-usgs thodson-usgs commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #440. _format_api_dates returned None when any non-blank element of a date argument matched no supported format, and both callers read None as "no date filter":

  • waterdata.get_ratings() sent the STAC search with no datetime and silently returned every rating.
  • The OGC getters (Water Data and NGWMN) sent an empty time=, and the service answered HTTP 400 "Invalid datetime format", naming no argument.

#440 fixed one input that took this path (".."). Any other unreadable value ("2024-13-45", "Jan 1 2024", ["2024-01-01", "tomorrow"]) still did.

Changes

  • ogc/dates.py: _format_one raises ValueError for a non-blank element it can't parse. The message names the caller's argument (name=) and the value, and gives accepted forms, including None for an open end. A range whose ends are all open still returns None (no filter). Returns/Raises/Notes updated.
  • Getter docstrings: the 15 time/begin/end/last_modified example blocks, plus get_ratings time and ngwmn.get_water_level datetime, now show the two-value list form with None for an open end. Until now that form was documented only in the private helper.
  • NEWS entry marked Behavior change. Only inputs that already failed are affected: for OGC getters, an HTTP 400 becomes a local ValueError. For get_ratings, a silently unfiltered result becomes an error.

Testing

  • New: test_format_api_dates_rejects_an_unreadable_bound (single, unsupported format, "Apr", range start/end), test_get_daily_rejects_an_unreadable_time_before_any_request, and test_get_ratings_rejects_an_unreadable_time_before_any_request. The two getter tests also assert that no request is sent.
  • The "Apr" case in test_format_api_dates pinned the old None. I moved it to the rejection test, where it still checks that "Apr" isn't mistaken for a duration.
  • Offline suite: 1254 passed under both TZ=UTC and TZ=America/Chicago. Branch coverage is 99.02%.
  • ruff check, ruff format --check, mypy, lint-imports, xenon, complexipy: pass.
  • Checked by hand: get_continuous(time="2024-13-45"), get_daily(last_modified=["bad", None]), and ngwmn.get_water_level(datetime=[..., "nope"]) each raise with the argument named.

Not in scope (already true on main)

  • A single string containing / is sent unchanged, so time="garbage/.." still reaches the service unvalidated. Validating each side would need to allow ISO 8601 start/duration intervals.
  • Non-string elements (pd.Timestamp, datetime) fail with AttributeError/TypeError instead of a ValueError that names the argument.

…ilter

_format_api_dates returned None when any non-blank element matched no
supported format. Callers treat None as "no date filter": get_ratings sent
its search without datetime and returned every rating, and the OGC getters
sent an empty time= that the service rejected with an HTTP 400 naming no
argument. DOI-USGS#440 fixed one input that hit this path (".."); every other
unreadable value still did.

The helper now raises ValueError naming the caller's argument and the bad
value, with the accepted forms, before any request. This covers time, begin,
end, datetime, last_modified, and the deprecated begin_utc/end_utc. A range
whose ends are all open still means no filter. The getter docstrings now show
the list form with None for an open end, which the new message points to.
@thodson-usgs
thodson-usgs force-pushed the fix/raise-on-unparseable-date-bound branch from 17708b5 to cc5c69b Compare October 8, 2026 14:31
@thodson-usgs
thodson-usgs marked this pull request as ready for review October 8, 2026 14:31
@thodson-usgs
thodson-usgs merged commit b3675aa into DOI-USGS:main Oct 8, 2026
11 checks passed
@thodson-usgs
thodson-usgs deleted the fix/raise-on-unparseable-date-bound branch October 8, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant