Fix #389: parse ISO-8601 string fields in relative_to_field()#700
Merged
Conversation
A windowed table configured with .relative_to_field(SomeField) reads the window timestamp from that field. When the field holds an ISO-8601 string (e.g. declared as str rather than datetime), WindowWrapper.get_timestamp returned the raw string, which then reached the Cython window range code and crashed with 'TypeError: must be real number, not str'. Parse a string timestamp with faust.utils.iso8601.parse (the same parser used for isodates model coercion) before converting to an epoch float, so relative_to_field works for both datetime and isoformat-string fields. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #700 +/- ##
==========================================
+ Coverage 94.14% 95.11% +0.96%
==========================================
Files 104 104
Lines 11136 11169 +33
Branches 1201 1206 +5
==========================================
+ Hits 10484 10623 +139
+ Misses 551 452 -99
+ Partials 101 94 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…on str Adds a functional test that drives the exact issue #389 scenario through the real windowing path: a Record whose `date_time` is a plain ISO-8601 `str`, a hopping table with `.relative_to_field(date_time)`, and `table[key] += n` applied under a mocked current event. Unlike the existing parametrized `test_get_timestamp` (which exercises `get_timestamp` in isolation), this runs the value all the way into `HoppingWindow.ranges`, so without the fix it fails with the exact `TypeError: must be real number, not str` from the issue. Both events use an identical message timestamp, so correct per-field bucketing proves the parsed field value (not the message time) drives the window. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
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.
What
A windowed table configured with
.relative_to_field(SomeField)derives the window timestamp from that field. When the field holds an ISO-8601 string — e.g. declared asstrinstead ofdatetime—WindowWrapper.get_timestamp()returned the raw string unchanged. That string then flowed into the Cython window-range code and crashed the agent:Fixes #389.
How
get_timestamp()already converteddatetime→ epoch float via.timestamp(). This adds astrbranch just before it: a string timestamp is parsed withfaust.utils.iso8601.parse— the same parser faust uses forisodatesmodel coercion — yielding adatetime, which then falls through to the existing.timestamp()conversion.So
relative_to_fieldnow works fordatetimefields (as before) and isoformat-string fields, instead of crashing deep in the windowing code.float/datetime/Nonepaths are unchanged.Test
Extended the parametrized
test_get_timestampintests/unit/tables/test_wrappers.pywith an ISO-8601 string input (DATETIME.isoformat()), asserting it maps to the same epoch timestamp as the equivalentdatetime. Fulltests/unit/tables/test_wrappers.pypasses (77 passed).🤖 Generated with Claude Code
Generated by Claude Code