Skip to content

fix: distinguish empty document content IDs - #13235

Closed
daleselaji-dev wants to merge 1 commit into
deepset-ai:mainfrom
daleselaji-dev:fix/document-empty-content-id-13234
Closed

daleselaji-dev wants to merge 1 commit into
deepset-ai:mainfrom
daleselaji-dev:fix/document-empty-content-id-13234

Conversation

@daleselaji-dev

Copy link
Copy Markdown

Problem

Document(content="") and Document(content=None) currently receive the same automatic ID. This can raise a misleading duplicate error for a same-batch write and can silently violate ID uniqueness across separate writes.

Root Cause

Document._create_id() normalizes self.content with self.content or None, collapsing the valid empty string into None before hashing.

Solution

Hash the validated content value directly so an empty string remains distinct from None.

Changes

  • Added a focused regression test proving empty-string and None content produce different IDs.
  • Added a release note for the automatic-ID behavior correction.

Testing

  • Baseline: PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run test:unit test/dataclasses/test_document.py — 38 passed.
  • Focused: same command after the change — 39 passed.
  • Risk-matched: PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run test:unit test/document_stores/test_in_memory.py — 370 passed, 8 skipped.
  • Format/lint: PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run fmt-check haystack/dataclasses/document.py test/dataclasses/test_document.py — passed.
  • Typecheck: PYTHONUTF8=1 PYTHONIOENCODING=utf-8 uvx hatch run test:types haystack/dataclasses/document.py test/dataclasses/test_document.py — passed.
  • git diff --check — passed.
  • Full test matrix was not run locally.

Compatibility/Risk

Automatic IDs for documents whose content is exactly "" will change. IDs for None content and other content values remain unchanged. Persisted stores containing empty-string documents may need an ID migration or re-write.

Notes for Reviewer

The implementation intentionally changes only the falsey-content normalization in _create_id; metadata and other ID inputs retain their existing serialization behavior. The change was verified on the current main snapshot and includes AI-assisted development disclosure per the repository contribution guide.

Linked Issue

Fixes #13234

@daleselaji-dev
daleselaji-dev requested a review from a team as a code owner October 13, 2026 02:35
@daleselaji-dev
daleselaji-dev requested review from julian-risch and removed request for a team October 13, 2026 02:35
@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@daleselaji-dev 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.
You have signed the CLA already but the status is still pending? Let us recheck it.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @daleselaji-dev, 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 removed the request for review from julian-risch October 13, 2026 03:44
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Oct 13, 2026
@HaystackBot
HaystackBot marked this pull request as draft October 13, 2026 03:44
@sjrl

sjrl commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR! We've decided not to change this behavior since it would change the auto-generated IDs of existing documents with empty content. See #13234 for details. Closing.

@sjrl sjrl closed this Oct 14, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document: content="" and content=None generate the same auto id

4 participants