-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MONGOID-5228 disallow _id to be updated on persisted documents #5542
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2f0a307
MONGOID-5228 - disallow _id to be updated on persisted documents
jamis 7ae322e
use a specialized error for immutability violations
jamis 95bb509
add a feature flag
jamis 82ffdc2
change the flag name, and account for existing nested attribute behavior
jamis d1b7762
wrong default for <9.0
jamis d8bde39
clean up a test that was unnecessarily sensitive to the _id changing
jamis 8dfbd5d
another test that was unnecessarily sensitive to _id changes
jamis 372997f
more tests that are too sensitive to _id changes
jamis 8ea4880
we need to allow _id mutations if the _id was previously nil
jamis db253ed
mention enforcement of _id immutability in the release notes
jamis 6edcc4b
Merge branch 'master' into 5228-disallow-_id-updates
jamis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mongoid | ||
module Errors | ||
|
||
# This error is raised when attempting the change the value of an | ||
# immutable attribute. For example, the _id attribute is immutable, | ||
# and attempting to change it on a document that has already been | ||
# persisted will result in this error. | ||
class ImmutableAttribute < MongoidError | ||
|
||
# Create the new error. | ||
# | ||
# @example Create the new error. | ||
# ImmutableAttribute.new(:_id, "1234") | ||
# | ||
# @param [ Symbol | String ] name The name of the attribute. | ||
# @param [ Object ] value The attempted set value. | ||
def initialize(name, value) | ||
super( | ||
compose_message("immutable_attribute", { name: name, value: value }) | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to
check_for_id_mutation!
orcheck_for_id_change!
? "Violation" in this context sounds like a malformed (i.e. non-BSON) ID. Similar withacceptable_id
ID below.