Skip to content

fix: make strict datetime filter comparison opt-in - #12257

Merged
sjrl merged 8 commits into
mainfrom
fix/consistent-datetime-filter-comparisons
Aug 7, 2026
Merged

fix: make strict datetime filter comparison opt-in#12257
sjrl merged 8 commits into
mainfrom
fix/consistent-datetime-filter-comparisons

Conversation

@sjrl

@sjrl sjrl commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Of the options listed in #12246, I opted for “equality could start reconciling,” aligning equality with the existing ordering behavior. Reconciliation can be disabled by setting the new keyword-only parameter strict_datetime_comparison=True. In strict mode, mixed timezone-aware and timezone-naive values are treated as non-matching rather than raising an error.

Added an opt-in strict_datetime_comparison keyword argument to document_matches_filter, InMemoryDocumentStore, and MetadataRouter. When enabled, timezone-naive and timezone-aware datetimes never match each other. By default, mixed-awareness datetimes continue to be reconciled by copying the timezone from the aware value to the naive one, and this behavior is now consistent across equality, membership, and ordering operators.

How did you test it?

New and existing tests

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Aug 7, 2026 6:03am

Request Review

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/routers
  metadata_router.py
  haystack/document_stores/in_memory
  document_store.py 616
  haystack/utils
  filters.py
Project Total  

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

@sjrl
sjrl marked this pull request as ready for review August 6, 2026 11:51
@sjrl
sjrl requested a review from a team as a code owner August 6, 2026 11:51
@sjrl
sjrl requested review from davidsbatista and julian-risch and removed request for a team and davidsbatista August 6, 2026 11:51
@sjrl

sjrl commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@julian-risch I've requested your review since you reviewed the most recent PR that introduced the discrepancy between equality and ordering for datetime comparisons so I believe you have the most context!

@sjrl sjrl self-assigned this Aug 6, 2026

@julian-risch julian-risch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Much better! Two things:

  • We should delete releasenotes/notes/fix-equality-iso-date-filter-4b7c9d2e1f6a8b03.yaml (the one from #11963 ). Technically not blocking this PR so I can also do that in a separate PR.
  • There is an issue with indentation of :param strict_datetime_comparison:. pre-existing issue for :param output_type: too. See the rendering: https://docs.haystack.deepset.ai/reference/next/routers-api#metadatarouter

@sjrl

sjrl commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@julian-risch both comments addressed in e5d6e0a

@sjrl
sjrl requested a review from julian-risch August 7, 2026 06:03
@sjrl
sjrl merged commit 49f8d2d into main Aug 7, 2026
26 checks passed
@sjrl
sjrl deleted the fix/consistent-datetime-filter-comparisons branch August 7, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ordering and equality filters disagree on naive vs tz-aware datetimes

2 participants