Skip to content
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

fix that JsonObjectBuilder.remove removes to much in certain cases #1798

Merged
merged 1 commit into from
Nov 8, 2023

Conversation

thjaeckle
Copy link
Member

This looks like a really small bug, but is has a huge impact:

  • Currently, for ThingMerged events the payload value can get "lost" before persisting a merge because of this bug

Here an inline policy is removed from the to-be-persisted JSON:

if (event instanceof ThingMerged) {
return super.performToJournalMigration(event, jsonObject)
.remove(POLICY_IN_THING_MERGED_VALUE_PAYLOAD); // remove the policy entries from thing merged payload

The JsonPointer to be removed is /value/_policy - if this _policy however does not exist and if the value does not even contain a JsonObject (which can be the case when using "merge", e.g. only updating one specific path to e.g. a JsonNumber), then the current implementation of ImmutableJsonObjectBuilder.remove will remove the value from the event.
That leads to the event missing its value in persistence and that leads to much pain and suffering when replaying events for that persistence actor, throwing exceptions on deserialization if the value is missing.

* also make ThingMongoEventAdapter more resilient, removing an inline policy from ThingMerged events

Signed-off-by: Thomas Jäckle <[email protected]>
@thjaeckle thjaeckle added the bug label Nov 8, 2023
@thjaeckle thjaeckle added this to the 3.4.1 milestone Nov 8, 2023
@thjaeckle thjaeckle self-assigned this Nov 8, 2023
@thjaeckle
Copy link
Member Author

@alstanchev @kalinkostashki a review would be nice - this is a really fundamental issue when using "MergeThing" commands :/

Copy link
Contributor

@alstanchev alstanchev left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@thjaeckle thjaeckle merged commit 93b73de into master Nov 8, 2023
3 checks passed
@thjaeckle thjaeckle deleted the bugfix/json-object-builder-remove branch November 8, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants