URL-encode Nightscout date filters instead of retrying with a mangled timestamp - #154
Merged
jwoglom merged 1 commit intoJul 21, 2026
Merged
Conversation
… timestamp arrow's isoformat() ends a timestamp with its UTC offset, e.g. '2026-07-16T00:00:00+02:00'. Placed raw into a query string, '+' is a reserved character that servers decode as a space, so Nightscout receives '2026-07-16T00:00:00 02:00' and answers 'could not parse as a valid ISO-8601 date'. Any user on a positive UTC offset hits this on every date-filtered query. The current workaround retries the request with 'T' replaced by a space (t_to_space) and treats a failure as 'no previous entry'. That gets a response, but it works around the symptom: the value is still mangled, every affected query costs two round-trips, and a genuinely empty result is indistinguishable from a rejected one. Percent-encoding the value fixes the cause: the offset survives, the first request succeeds, and the t_to_space fallback and its retry wrapper are no longer needed and are removed. Adds tests for time_range(): that a positive offset is encoded rather than emitted raw, that the encoded value round-trips back to the original instant, that negative offsets and 'Z' still parse, and the bounds/no-bounds cases. There was no coverage of time_range() before. The encoding test fails on master with '+' present in the query and passes with this change. Running with this in my EU deployment since May.
Owner
|
Thanks - will merge! |
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.
arrow'sisoformat()ends a timestamp with its UTC offset, e.g.2026-07-16T00:00:00+02:00. Placed raw into a query string,+is a reserved character that servers decode as a space, so Nightscout receives2026-07-16T00:00:00 02:00and answers "could not parse as a valid ISO-8601 date". Every user on a positive UTC offset hits this on every date-filtered query.The current workaround
time_range()takes at_to_spaceflag, and eachlast_uploaded_*method wraps its request so that a failure retries withTreplaced by a space, treating a second failure as "no previous entry".That gets a response, but it works around the symptom rather than the cause: the value is still mangled, every affected query costs two round-trips, and a genuinely empty result becomes indistinguishable from a rejected one.
This change
Percent-encodes the value instead. The offset survives, the first request succeeds, and the
t_to_spacefallback and its retry wrapper become dead code, so they are removed:Tests
There was no coverage of
time_range()before. This adds tests that a positive offset is encoded rather than emitted raw, that the encoded value round-trips back to the original instant, that negative offsets andZsuffixes still parse, and the both-bounds / no-bounds cases.The encoding test fails on current master:
and passes with this change.
I have been running this in my EU deployment since May. Split out of #143, which bundled too many unrelated changes to be reviewable.