Repository navigation
fix(ogc): read each side of a "start/end" interval string like the list form - #443
Open
bhaskargurram-ai wants to merge 1 commit into
Open
bhaskargurram-ai wants to merge 1 commit into
bhaskargurram-ai wants to merge 1 commit into
Conversation
…st form
_format_api_dates sent any single string containing "/" unchanged. The
same range spelled as the documented string ("2024-01-01T10:00:00/..")
and as the list (["2024-01-01T10:00:00", None]) could select different
data: the string skipped the local-to-UTC conversion of naive times, the
offset-to-Z conversion, and the date truncation for date-only
collections, and "not-a-date/also-bad" reached the service unvalidated.
Split the string on its "/" and format each side as a list element is
formatted, so an unreadable side raises ValueError naming the caller's
argument before any request. An empty side becomes "..", and "../.."
means no filter, as [None, None] does. One side may still be an ISO 8601
duration paired with an instant ("2024-01-01/P7D"), kept unchanged; any
other shape (three sides, two durations, a duration with an open end)
raises ValueError naming the argument. A lone duration ("P7D") is
unchanged.
Follow-up named in DOI-USGS#441.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up named in #441 ("a single string containing
/is still sent unchanged, sotime="garbage/.."reaches the service unvalidated").Problem
_format_api_datesreturned any single string containing/unchanged. As a result, the same range spelled the two documented ways could select different data:time=["2024-01-01T10:00:00", None]2024-01-01T17:00:00Z/..time="2024-01-01T10:00:00/.."2024-01-01T10:00:00/..(no local-to-UTC conversion)daily,time=["2024-01-01T10:00:00Z", "2024-02-01T00:00:00Z"]2024-01-01/2024-02-01daily,time="2024-01-01T10:00:00Z/2024-02-01T00:00:00Z"time="not-a-date/also-bad"time="2024-01-01T00:00:00Z/"dailyanswers 400,continuous500Change
/is split on that/, and each side is formatted exactly like an element of the two-value list form. Sides get the same parsing, naive-local-to-UTC and offset-to-Zconversion, and date truncation for date-only collections.ValueError(time could not be read as a date or datetime: 'not-a-date'. ...) before any request is sent...), and"../.."means no date filter, as[None, None]does."2024-01-01/P7D","P7D/2024-01-08"), sent unchanged as before.ValueErrornaming the argument: three sides, two durations, or a duration with an open end."P7D"is unchanged.One question for review: while testing I found that
api.waterdata.usgs.gov/ogcapi/v1rejects both duration-interval forms (dailytime=2024-01-01/P7Dgives 400 "Invalid datetime format",time=P7D/2024-01-08gives 400 "Invalid ISO 8601 duration"; the same forcontinuouswithPT2H). This PR keeps passing them through, so nothing that worked before changes. If you would rather reject them locally, it is a small change to_format_interval.Tests
tests/waterdata_utils_test.py:start/durationandduration/end;"../.."gives None;tests/waterdata_test.py:get_daily(time="not-a-date/also-bad")raises and sends no request.The new cases fail on
mainand pass with this change. The full offline suite passes underTZ=UTCandTZ=America/Chicago, coverage is 98.99% against the 98.9 ratchet withdates.pyat 100%, andruff check,ruff format --check,mypy,lint-imports,xenonandcomplexipyare clean.This touches the same module as #442, but in a different part of
_format_api_dates. The only conflict between the two branches is the top entry inNEWS.md.