Skip to content

Fix #389: parse ISO-8601 string fields in relative_to_field()#700

Merged
wbarnha merged 2 commits into
masterfrom
claude/fix-389-relative-field-str
Jul 21, 2026
Merged

Fix #389: parse ISO-8601 string fields in relative_to_field()#700
wbarnha merged 2 commits into
masterfrom
claude/fix-389-relative-field-str

Conversation

@wbarnha

@wbarnha wbarnha commented Jul 19, 2026

Copy link
Copy Markdown
Member

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 as str instead of datetimeWindowWrapper.get_timestamp() returned the raw string unchanged. That string then flowed into the Cython window-range code and crashed the agent:

TypeError: must be real number, not str
  File "faust/_cython/windows.pyx", line 62, in faust._cython.windows.HoppingWindow.ranges

Fixes #389.

How

get_timestamp() already converted datetime → epoch float via .timestamp(). This adds a str branch just before it: a string timestamp is parsed with faust.utils.iso8601.parse — the same parser faust uses for isodates model coercion — yielding a datetime, which then falls through to the existing .timestamp() conversion.

So relative_to_field now works for datetime fields (as before) and isoformat-string fields, instead of crashing deep in the windowing code. float/datetime/None paths are unchanged.

Test

Extended the parametrized test_get_timestamp in tests/unit/tables/test_wrappers.py with an ISO-8601 string input (DATETIME.isoformat()), asserting it maps to the same epoch timestamp as the equivalent datetime. Full tests/unit/tables/test_wrappers.py passes (77 passed).

🤖 Generated with Claude Code


Generated by Claude Code

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

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.11%. Comparing base (3073eb9) to head (7768472).
⚠️ Report is 21 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…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
@wbarnha
wbarnha added this pull request to the merge queue Jul 21, 2026
Merged via the queue into master with commit da18659 Jul 21, 2026
25 checks passed
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.

relative_to_field raised error when the field is string type(isoformat)

1 participant