fix: keep the type of meta values in the Document ID hash #13847
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 552 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.378
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #13847"
general
weight: 0.35
1AbdullahButt
Related Issues
No issue for this, I hit it while working on something else.
Proposed Changes:
Document._create_idbuilds the hash fromjson.dumps(self.meta, sort_keys=True, default=str). Two things in there drop the type of a value:json.dumpswrites(1, 2)as[1, 2], the same as a list.default=strand becomes the string"{1, 2}".Both cases make unrelated documents collide:
InMemoryDocumentStore.write_documents([...])then raisesDuplicateDocumentError: ID 'de0fa6eb5c49...' already exists, and withDuplicatePolicy.OVERWRITEthe second document is silently dropped. Indexing a JSONL where the same field is sometimes a list and sometimes a tuple from the source format is enough to hit it.The fix walks
metabefore hashing and marks the two problematic types:{"__tuple__": [...]}, keeping the element order{"__set__": [...]}, sorted by the JSON of each element so that iteration order doesn't leak into the IDEverything else is passed through untouched, which is what keeps existing IDs stable:
json.dumpsnever sees the marker dicts unless the metadata actually contained a tuple or a set, so documents whose metadata only uses JSON types hash exactly as before. The hardcoded IDs intest_init_with_legacy_fieldsandtest_initstill pass, andtest_to_dictstill assertsdocument["id"] == doc._create_id().I did not touch the empty vs
Nonecontent case, there are a few closed issues and PRs about that and I didn't want to reopen a settled discussion here.How did you test it?
New tests in
test/dataclasses/test_document.py:test_id_distinguishes_meta_value_types, parametrized over list vs tuple, set vs itsstr(), set vs list, nested lists vs nested tuples, and two different nestings of the same tuple.test_id_of_set_meta_is_independent_of_iteration_order:{1, 2, 3}and{3, 2, 1}give the same ID, which is what the sorting is for.test_id_of_tuple_meta_depends_on_element_order:(1, 2)and(2, 1)don't.test_documents_with_different_meta_types_can_be_stored_together: writes the list and the tuple document into anInMemoryDocumentStoreand gets 2 documents back.Before:
pytest test/dataclasses/test_document.pygives 4 failed, 58 passed. After: 62 passed.pytest test/dataclasses test/document_stores/test_in_memory.pygives 794 passed, 8 skipped. The one failure in that run,test_image_content_from_url_wrong_mime_type, fails on a clean main too (it fetches a URL).ruff checkandruff format --checkare clean.Notes for the reviewer
Document.to_dict()andDocument.metaare unchanged, so round trips and serialization are not affected._make_metadata_value_hashableinutils/misc.pyhas a similar blind spot for sets, but it's used by the evaluators for grouping and not for IDs. I left it alone to keep this PR focused.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.