Skip to content

Fix/ordering filter mixed str datetime#11679

Open
rautaditya2606 wants to merge 2 commits into
deepset-ai:mainfrom
rautaditya2606:fix/ordering-filter-mixed-str-datetime
Open

Fix/ordering filter mixed str datetime#11679
rautaditya2606 wants to merge 2 commits into
deepset-ai:mainfrom
rautaditya2606:fix/ordering-filter-mixed-str-datetime

Conversation

@rautaditya2606

@rautaditya2606 rautaditya2606 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Related Issues

fixes #11678

Proposed Changes

  • Update _prepare_ordering_comparison() to only call _parse_date() on operands that are actually strings.
  • Normalize naive/aware datetimes via _ensure_both_dates_naive_or_aware() when both operands resolve to datetime.
  • Wrap >, >=, <, <= operators in try/except TypeErrorFilterError to preserve existing error behavior.
  • Added regression tests for aware datetime vs string date and naive datetime vs aware ISO string.
  • Added release note.

How did you test it?

hatch run test:unit test/utils/test_filters.py -k document_matches_filter

92 tests passed.

Notes for the reviewer

  • Root cause: _prepare_ordering_comparison() called _parse_date() on both operands when either was a string, crashing when the other was already a datetime.
  • Mixed string/datetime comparisons are valid — ISO date strings in Document.meta compared against datetime filter values is a real use case.
  • TypeError wrapping keeps error behavior consistent with existing Haystack conventions.

Checklist

  • Read contributors guidelines and code of conduct
  • Updated related issue
  • Added unit tests and updated docstrings
  • Used conventional commit type in PR title
  • Documented code
  • Added release note
  • Run pre-commit hooks and fixed any issues

@rautaditya2606 rautaditya2606 requested a review from a team as a code owner June 18, 2026 10:27
@rautaditya2606 rautaditya2606 requested review from julian-risch and removed request for a team June 18, 2026 10:27
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

@rautaditya2606 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@rautaditya2606 rautaditya2606 force-pushed the fix/ordering-filter-mixed-str-datetime branch from 8b3fe81 to 057b2ca Compare June 18, 2026 10:32
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/utils
  filters.py
Project Total  

This report was generated by python-coverage-comment-action

@rautaditya2606 rautaditya2606 force-pushed the fix/ordering-filter-mixed-str-datetime branch from 7393f5d to 86558f3 Compare June 19, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: FilterError when comparing string metadata dates with datetime objects using ordering operators

1 participant