Fix save() OperationFailure with use_revision=True and keep_nulls=False#1281
Open
roman-right wants to merge 1 commit intomainfrom
Open
Fix save() OperationFailure with use_revision=True and keep_nulls=False#1281roman-right wants to merge 1 commit intomainfrom
roman-right wants to merge 1 commit intomainfrom
Conversation
…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
staticxterm
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Both save() and save_changes() call get_top_level_nones(), so the fix covers both code paths.
Tests
Fixes #958