Skip to content

Comments

Fix save() OperationFailure with use_revision=True and keep_nulls=False#1281

Open
roman-right wants to merge 1 commit intomainfrom
fix/issue-958-revision-keep-nulls
Open

Fix save() OperationFailure with use_revision=True and keep_nulls=False#1281
roman-right wants to merge 1 commit intomainfrom
fix/issue-958-revision-keep-nulls

Conversation

@roman-right
Copy link
Member

Problem

When a Document has both use_revision=True and keep_nulls=False, calling save() on a new document raises OperationFailure because revision_id (initially None) ends up in both the update pipeline's set and unset operators.

MongoDB rejects updates where the same path appears in both operators.

Fix

  • get_top_level_nones() now excludes revision_id when use_revision=True
  • get_dict() now respects the exclude parameter by subtracting excluded fields from the include set

Both save() and save_changes() call get_top_level_nones(), so the fix covers both code paths.

Tests

  • test_save_with_revision_and_keep_nulls_false - new document insert via save()
  • test_update_with_revision_and_keep_nulls_false - update existing doc via save()

Fixes #958

…ionFailure

When both settings are enabled, revision_id (initially None on new
documents) appears in both \ (from SetRevisionId) and \
(from get_top_level_nones), causing MongoDB to reject the update.

Fix: exclude revision_id from get_top_level_nones when use_revision
is enabled — revision_id is managed independently by SetRevisionId
in the update pipeline. Also ensure get_dict respects the exclude
parameter by subtracting excluded fields from the include set.

Fixes #958
Copy link
Contributor

@CAPITAINMARVEL CAPITAINMARVEL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CAPITAINMARVEL CAPITAINMARVEL requested review from a team February 16, 2026 13:09
@staticxterm staticxterm requested a review from a team February 19, 2026 19:09
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.

[BUG] save() results in OperationFailure if use_revision=True and keep_nulls=False

3 participants