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.
tofieldset: Add tests to show it already allow duplicates #249
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
tofieldset: Add tests to show it already allow duplicates #249
Changes from all commits
0e49988
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
cc @jpbetz
This code is mostly irrelevant because we only use
ToFieldSet
on objects that are applied, and we should never allow apply to have duplicates (now, that being said, I'm curious if this whole change even makes sense?). I still wanted to illustrate that when someone will update with duplicates items, we will just give them ownership of the associative key and that's it, as a way to indicate that they own that key multiple times. WDYT?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.
One drawback of this, but I don't know if we can solve it anyway, is that if someone applies one item, and then it gets updated into two items, that item won't be pruned when it's removed from the applied configuration, meaning it can no longer be removed with server-side apply. I think that's reasonable.
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.
If apply can never have duplicates why are we making SMD ToFieldSet tolerate duplicates? How do Updates get the list of fields to own if not via ToFieldSet?
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.
Context, we're trying to solve #234
For built-ins, the
listType=map
is used a little loosely, and we don't have a great way to address that, except for accepting some duplicates. We still can't apply duplicates, but right now you can't apply an objects that has these duplicates.By using "Compare", they own the fields that they changed, since we don't know exactly what they intended to own.
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.
Is ToFieldSet invoked on the final merged object, or the partial patch? If it is invoked on the partial patch aren't there no duplicates and this PR has no effect?
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.
Correct, that's more or less what I said in the PR body:
But:
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.
Why wouldn't it be pruned?
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.
Because when you update to multiple items, it steals the ownership of the whole item and we don't prune things that you don't have ownership over.
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.
It sounds like you do own it if it steals ownership of the whole item? Do you only have ownership of one copy? Can you share example of the behavior for this. I would expect that you have ownerhsip of the whole duplicated field, and when you submit an UPDATE or PATCH that does not include it, then no one has ownership, and it is pruned.
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.
Using sets, since it's a little simpler:
Apply, "applier": [1]
Update, "updater": [1, 1] # Updater steals ownership of 1
Apply, "applier": [] # 1 is not pruned because it's owned by updater.
Final object: [1, 1]
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.
That seems like correct behavior to me. What if it was a map typed list with duplicate keys but unequal objects?
Apply, "applier": [ObjWithKeyA]
Update, "updater": [ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] # Should be three copies of 'A'?
Apply, "applier": [] # is A pruned?
Whats the final object
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.
Very good point.
So first of all,
Update
replaces the whole list, so if you doyou end-up with that exact object.
Second, the way this is meant to work, is that if you have duplicate, you own the key and the key only, so here's what happens in your scenario:
Apply, "applier": [ObjWithKeyA] -> applier owns ObjWithKeyA
Update, "updater": [ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] -> duplicates, updater owns just "KeyA" (none of the fields)
Apply, "applier": [] # is A pruned? no
Whats the final object
[ObjWithKeyAButSlighlyDifferent, ObjWithKeyAButAlsoDifferent] with KeyA owned by updater.
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.
i think thats reasonable