allow referencing existing objects when part of the conflict set#531
Open
mpareja wants to merge 1 commit intoautomerge:mainfrom
Open
allow referencing existing objects when part of the conflict set#531mpareja wants to merge 1 commit intoautomerge:mainfrom
mpareja wants to merge 1 commit intoautomerge:mainfrom
Conversation
mpareja
commented
Feb 10, 2023
| createNestedObjects(obj, key, value, insert, pred, elemId) { | ||
| if (value[OBJECT_ID]) { | ||
| throw new RangeError('Cannot create a reference to an existing document object') | ||
| const object = this.updated[obj] || this.cache[obj] |
Author
There was a problem hiding this comment.
This falls down when the array has nested objects.
A makeList operation is added and createNestedObjects is called recursively. The updated and cache maps haven't yet learned about the newly (?) added node.
it('should allow referencing an existing list of objects that is part of the conflict set', () => {
s2 = Automerge.clone(s1)
s1 = Automerge.change(s1, doc => doc.list = [{ field: 'a' }])
s2 = Automerge.change(s2, doc => doc.list = [{ field: 'b' }])
const result = Automerge.merge(s1, s2)
const conflicts = Automerge.getConflicts(result, 'list')
// Should not throw "Cannot create a reference to an existing document object"
Automerge.change(result, doc => {
doc.list = Object.values(conflicts)[0]
})
})
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.
Issue automerge/automerge#526 demonstrated that it was not possible to resolve a conflict by choosing one of the conflicting objects or arrays. The following change allows setting a nested object to be an existing object reference so long as the referenced object id is currently listed as one of the conflicts for the key.