Skip to content

fix: preserve colliding metadata keys in Document.__eq__#11982

Draft
NIK-TIGER-BILL wants to merge 1 commit into
deepset-ai:mainfrom
NIK-TIGER-BILL:fix/document-eq-metadata-collision
Draft

fix: preserve colliding metadata keys in Document.__eq__#11982
NIK-TIGER-BILL wants to merge 1 commit into
deepset-ai:mainfrom
NIK-TIGER-BILL:fix/document-eq-metadata-collision

Conversation

@NIK-TIGER-BILL

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

previously called , and defaults to . With flattening, is spread under the document's own top-level fields, so any metadata key that collides with a field name (uid=0(root) gid=0(root) groups=0(root), , , …) is silently overwritten by the document's own field before the comparison happens. As a result, two s with identical fields but different colliding metadata keys compared as equal — for example vs with and both reported as equal.

This change makes call so metadata keys are compared verbatim and collision cases are reported correctly. The unflattened representation already exists for exactly this kind of use case (no info is lost) and accepts either form, so no API surface changes.

How did you test it?

Added three regression tests in :

  • — the original bug repro from the issue, plus and collisions.
  • — companion case: identical colliding meta keys must still compare equal.
  • The existing , , , and continue to pass, confirming that the documented equality behaviour for non-colliding Documents is preserved.

All checks verified locally by importing the dataclass module directly with stubbed package hierarchy (full env not available in this sandbox).

Notes for the reviewer

This is intentionally a minimal one-line semantic change with no API surface change. The fix targets the symptom reported in #11969; the broader flatten/unflatten asymmetry between and is tracked separately upstream and is intentionally out of scope here.

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:.
  • I have documented my code.
  • I have added a release note file under releasenotes/notes/.
  • I have run pre-commit hooks and fixed any issue. (Note: pre-commit was not run in this sandbox; flake8/black/isort only check style and the diff is mechanical.)

…11969)

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@NIK-TIGER-BILL
NIK-TIGER-BILL requested a review from a team as a code owner July 13, 2026 10:05
@NIK-TIGER-BILL
NIK-TIGER-BILL requested review from anakin87 and removed request for a team July 13, 2026 10:05
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


NIK-TIGER-BILL seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/dataclasses
  document.py
Project Total  

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

@anakin87 anakin87 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.

Please make the CLA check pass: you might need to rewrite the Git history.

I also left some comments.

Ping me when ready.

Comment on lines +140 to +146
doc3 = Document(content="hello", meta={"score": 0.5})
doc4 = Document(content="hello", meta={"score": 0.9})
assert doc3 != doc4

doc5 = Document(content="hello", meta={"content": "from_meta"})
doc6 = Document(content="hello", meta={"content": "also_from_meta_but_different"})
assert doc5 != doc6

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.

Suggested change
doc3 = Document(content="hello", meta={"score": 0.5})
doc4 = Document(content="hello", meta={"score": 0.9})
assert doc3 != doc4
doc5 = Document(content="hello", meta={"content": "from_meta"})
doc6 = Document(content="hello", meta={"content": "also_from_meta_but_different"})
assert doc5 != doc6
doc3 = Document(id="same_id", content="hello", meta={"score": 0.5})
doc4 = Document(id="same_id", content="hello", meta={"score": 0.9})
assert doc3 != doc4
doc5 = Document(id="same_id", content="hello", meta={"content": "from_meta"})
doc6 = Document(id="same_id", content="hello", meta={"content": "different_from_meta"})
assert doc5 != doc6


def test_equality_preserves_meta_keys_colliding_with_top_level_fields():
"""
Regression test for #11969.

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.

  • no need to mention the issue
  • shorter docstring explanation


def test_equality_with_colliding_meta_keys_when_meta_actually_matches():
"""
Companion to the regression test for #11969.

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.

no need to mention the issue

@anakin87 anakin87 added the cla-pending PR is in draft until the contributor signs the CLA label Jul 23, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @NIK-TIGER-BILL, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot marked this pull request as draft July 23, 2026 09:12
@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @NIK-TIGER-BILL, just a friendly reminder: this PR is still in draft because the Contributor License Agreement (CLA) hasn't been signed yet. We'd love to review your contribution! Please sign the CLA via the link in the license/cla check, and this PR will automatically be marked ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-pending PR is in draft until the contributor signs the CLA topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Document.__eq__ ignores colliding metadata keys during equality comparison

4 participants