Avoid inconsistent modified attributes state after object updates were rejected due to validation errors#10939
Open
julianbrost wants to merge 1 commit into
Open
Avoid inconsistent modified attributes state after object updates were rejected due to validation errors#10939julianbrost wants to merge 1 commit into
julianbrost wants to merge 1 commit into
Conversation
Otherwise, the value may be rejected, leaving original_attributes in the already changed but now inconsistent state.
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.
Update
original_attributesonly after validation of the new value. Otherwise, the value may be rejected, leaving original_attributes in the already changed but now inconsistent state.I noticed that issue while working on #10940, but I've created this as a separate PR as this can also be viewed as an independent issue. As shown by the tests below, this can already be triggered even without that PR.
Tests
The following test creates an object, then tries to modify a custom variable with an invalid value and then observes the resulting behavior.
Before (master as of 8ff3d58)
Create an object for testing (having non-empty
varsseems to be important for reproducing this):Attempt to modify its custom variables without success (as expected, it fails):
Now query the object, in particular the
original_attributes, you'll see that even though the update was rejected,vars.oopswas added there:Now restart Icinga 2:
And perform the very same query again, where you can observe, that now the object has a mysterious
vars.oopswith valuenull:This PR (as of 0332ead)
If the object is still there from the previous test, make sure to delete it.
Creating (PUT) and attempting to update (POST) produces the same responses, the difference only starts to show with the following GET request, where nothing was added to
original_attributes:Which - in contrast to the previous behavior - also stays the same across a restart of Icinga 2.
Additional Information
The value of
original_attributesis important here as this is used to create/var/lib/icinga2/modified-attributes.confwhich then contains something like this with the unfixed version, explaining why this suddenly appears withinvarsafter the restart: