Skip to content

fix: normalize ISO date equality filters - #11963

Merged
julian-risch merged 5 commits into
deepset-ai:mainfrom
Aarkin7:fix/iso-date-filter-equality
Aug 4, 2026
Merged

fix: normalize ISO date equality filters#11963
julian-risch merged 5 commits into
deepset-ai:mainfrom
Aarkin7:fix/iso-date-filter-equality

Conversation

@Aarkin7

@Aarkin7 Aarkin7 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

This fixes a gap in metadata filtering where ==!=in, and not in were still comparing ISO timestamps as raw strings. That meant equivalent values like 2025-02-03T12:45:46Z and 2025-02-03T12:45:46+00:00 could silently miss matching documents.

The fix normalizes date-like values for equality-style filters so they behave consistently with the ordering operators. I also added regression tests for both the filter helper and the InMemoryDocumentStore path, plus a release note.

How did you test it?

  • Ran hatch run fmt on the touched files
  • Ran hatch run test:unit test/utils/test_filters.py
  • Ran targeted InMemoryDocumentStore filter tests
  • Manually verified that == and in now return matches for equivalent ISO timestamps

Notes for the reviewer

The main logic change is in haystack/utils/filters.py.

The most useful review points are:

  • the equality normalization helper in filters.py
  • the new regressions in test/utils/test_filters.py
  • the end-to-end store check in test/document_stores/test_in_memory.py

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.

@Aarkin7
Aarkin7 requested a review from a team as a code owner July 10, 2026 17:54
@Aarkin7
Aarkin7 requested review from julian-risch and removed request for a team July 10, 2026 17:54
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@Aarkin7

Aarkin7 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

The remaining CI failures appear unrelated to this PR. They’re in test/components/generators/chat/test_openai_responses*.py with InputTokensDetails.cache_write_tokens validation errors. This PR only touches filter logic/tests and a release note.

Narrows the equality normalization to strict ISO 8601 parsing, matching what
the document store integrations do, and leaves the ordering operators exactly
as they were on main.

- Parse with datetime.fromisoformat, falling back to dateutil.parser.isoparse
  only for the spellings Python 3.10 rejects (notably a trailing "Z"). The
  lenient dateutil.parser.parse could read non-dates as dates.
- Never compare a naive value to an aware one. Adopting the other operand's
  tzinfo, as the ordering path does, would report two different instants as
  equal and make "!=" drop documents that do not match.
- Short-circuit on the identical case, so same-format date fields cost what
  they did before this change on the per-document filtering hot path.
- Keep _equal total: unparsable date-shaped values fall back to comparing as
  strings instead of raising.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Aug 4, 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 for the initiative @Aarkin7 ! I slightly adjusted the PR and it looks good to me now.

@julian-risch
julian-risch enabled auto-merge (squash) August 4, 2026 08:52
@github-actions

github-actions Bot commented Aug 4, 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

@julian-risch
julian-risch disabled auto-merge August 4, 2026 09:10
@julian-risch
julian-risch merged commit 3ec9d08 into deepset-ai:main Aug 4, 2026
21 of 23 checks passed
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.

'==' and 'in' filters silently miss equivalent ISO timestamps (Z vs +00:00)

2 participants