Skip to content

fix(weave): normalize datetime literals in feedback/ORM query path#6991

Open
gtarpenning wants to merge 3 commits into
masterfrom
gtarpenning/fix-feedback-datetime
Open

fix(weave): normalize datetime literals in feedback/ORM query path#6991
gtarpenning wants to merge 3 commits into
masterfrom
gtarpenning/fix-feedback-datetime

Conversation

@gtarpenning
Copy link
Copy Markdown
Member

@gtarpenning gtarpenning commented May 28, 2026

Summary

  • feedback_query 500'd on created_at filters: ISO-8601 strings carrying a T separator / Z suffix (e.g. 2026-05-27T17:49:15.491230Z) can't be compared against the DateTime64(3) column, so ClickHouse raises TYPE_MISMATCH (code 53). The generic ORM where path now normalizes datetime-column literals to ClickHouse's canonical YYYY-MM-DD HH:MM:SS.ffffff form, mirroring the existing calls-query-builder fix.
  • To avoid duplicating that logic, the two datetime helpers (parse_string_to_utc_timestamp, timestamp_to_datetime_str) and the operand converter move down into orm.py (the base layer both paths import; calls_query_builder can't be imported back into orm). The calls path now delegates to the shared maybe_convert_datetime_operands instead of its own copy.
  • Scope: only the binary comparison ops ($eq/$gt/$lt/$gte/$lte) normalize datetime literals, matching the calls path. $in against a datetime column is unchanged (different operand shape, and exact-timestamp IN lists aren't a real query pattern).
  • WB-34897

Testing

unit coverage in test_orm.py for the conversion (incl. a non-datetime-column control) + a functional feedback_query test that filters on created_at and asserts on the returned row; calls path delegates to the shared helper so existing calls coverage applies.

feedback_query 500'd on created_at filters because ISO-8601 strings with
a T separator / Z suffix can't be compared against a DateTime64 column
(TYPE_MISMATCH, code 53). The generic ORM where-path now normalizes
datetime-column literals to ClickHouse's canonical
YYYY-MM-DD HH:MM:SS.ffffff form, mirroring the calls query builder.

The shared datetime helpers and the operand converter move down into
orm.py (the base layer both paths depend on); the calls path delegates
to the shared maybe_convert_datetime_operands.

WB-34897

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gtarpenning gtarpenning marked this pull request as ready for review May 28, 2026 18:37
@gtarpenning gtarpenning requested a review from a team as a code owner May 28, 2026 18:37
…operands

Move maybe_convert_datetime_operands into process_binary_operands (the
single chokepoint for all five comparison ops) instead of calling it at
each branch, and drop the redundant date-only branch in
parse_string_to_utc_timestamp -- datetime.fromisoformat already parses
YYYY-MM-DD as naive midnight, which the existing naive-as-UTC path
handles identically.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 96.22642% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
weave/trace_server/orm.py 96.07% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Query real fields (id, feedback_type, payload) and assert on the
returned row instead of only count(*), so the datetime-filter path is
exercised as a full round-trip. Also trim an overclaim in the
maybe_convert_datetime_operands docstring (index pruning is table-
dependent, not guaranteed in the generic ORM path).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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