Skip to content

fix: route MongoBaseStore.persist_data through __setitem__, not the leaf - #13

Merged
thorwhalen merged 1 commit into
masterfrom
fix/mongobasestore-persist-data
Sep 22, 2026
Merged

thorwhalen merged 1 commit into
masterfrom
fix/mongobasestore-persist-data

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Summary

Fixes the destructive gap identified in #11 (part 1 of 2 — the docs/design gap in part 2 was independently resolved by #10/mongodol/views.py's bulk-read resolver, a different and more general mechanism than the one #11 originally proposed for that part; see triage comment for detail).

persist_data was the one value-side method MongoBaseStore did not override (unlike its six siblings: contains_value/iter_values/contains_item/iter_items/append/extend). Being delegated leaf-bound, it bypassed both _id_of_key and _data_of_obj and issued a whole-document replace_one(upsert=True) built straight from the outer (untransformed) object — silently destroying every field not present in the outer shape on any store built with set_key_and_data_fields.

Fix

Adds MongoBaseStore.persist_data(data, key=None), routing through self[key] = data so the wrapper's own key/data transforms apply — the same pattern as its six siblings. key defaults to being inferred from data[ID] for backward compatibility with the previous call signature (persist_data(data)), matching the exact remediation #11 proposed and verified against the leaf/wrapper delegation mechanics.

Test plan

  • wads ci-local (format + lint) green; the test leg needs a live mongo, unavailable in this sandbox — deferred to hosted CI (mongo:5.0 service container), public repo.
  • gh pr checks --watch green before merge.

Closes #11

🤖 Generated with Claude Code

https://claude.ai/code/session_011HSBVhDjRU4apSLcRkavv9

persist_data was the one value-side method MongoBaseStore did not override,
so it was delegated leaf-bound: it bypassed both _id_of_key and _data_of_obj
and issued a whole-document replace_one(upsert=True) built from the outer
(untransformed) object. On any store built with set_key_and_data_fields this
silently destroyed every field not present in the outer shape and rewrote the
document in the wrong shape.

Add MongoBaseStore.persist_data alongside its six siblings
(contains_value/iter_values/contains_item/iter_items/append/extend), routing
through self[key] = data so the wrapper's own key/data transforms apply. key
defaults to being inferred from data[ID] for backward compatibility.

Closes #11

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 3680460 into master Sep 22, 2026
10 checks passed
@thorwhalen
thorwhalen deleted the fix/mongobasestore-persist-data branch September 22, 2026 13:30
@thorwhalen

Copy link
Copy Markdown
Member Author

Note (added after merge, per updated crowsnest review policy): this change was self-reviewed only — no independent adversarial review was run before merging. Flagging for the record; the fix itself (routing persist_data through setitem) is additive-only and covered by hosted CI, but a second pass would be prudent if this is revisited.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leaf-bound delegation: persist_data bypasses data_of_obj/id_of_key and destroys documents; shipped stores.py classes miss the MongoBaseStore remedy

1 participant