fix: FilterError when comparing string metadata dates with datetime objects#11700
fix: FilterError when comparing string metadata dates with datetime objects#11700milljer wants to merge 1 commit into
Conversation
…to datetime objects _prepare_ordering_comparison unconditionally parsed both operands as date strings, so a datetime filter value would fail to parse and raise FilterError. Only parse operands that are actually strings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@milljer is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
Good fix — the One thing worth flagging from a regulated-domain (legal/compliance) angle: this Specifically, ISO-8601 strings (
For legal/regulatory corpora this carries compliance weight, not just convenience weight. The filter A small extension that would harden this: when |
Related Issues
bug: FilterError when comparing string metadata dates with datetime objects using ordering operators#11678Proposed Changes:
document_matches_filterraised aFilterErrorwhen comparing a string date inDocument.meta(e.g."2024-01-01") against adatetimefilter value using ordering operators (>,>=,<,<=), even though storing dates as ISO strings in metadata is a common, valid pattern.Root cause:
_prepare_ordering_comparisoninhaystack/utils/filters.pyunconditionally called_parse_dateon both operands whenever either one was a string, but_parse_dateonly acceptsstrand raised when given an already-parseddatetime.Fix: only call
_parse_dateon an operand that isn't already adatetime.How did you test it?
> operator with datetime filter value and ISO 8601 string Document value) intest/utils/test_filters.py.hatch run test:unit -k test_filters(91 passed, including the 4 existing tests that cover non-date string/int comparisons still raisingFilterErroras before).hatch run test:typesandhatch run fmt, both clean.Notes for the reviewer
The fix only skips
_parse_datewhen an operand is already adatetime; it still attempts_parse_dateon non-string, non-datetime operands (e.g.int) so existing behavior — raisingFilterErrorfor nonsensical string/non-date comparisons — is preserved.Checklist
fix:.