-
Notifications
You must be signed in to change notification settings - Fork 3
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
Relax oneof set fields validation #43
Conversation
@@ -70,11 +62,19 @@ if !dstOk && dst.%s != nil { | |||
fPath = m.ctx.Name(f.OneOf()).String() | |||
} | |||
|
|||
buildIndented(buf, tabCount, fmt.Sprintf(`if src != nil { | |||
if f.InOneOf() { |
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.
We need to check if the source type actually matches, not only that it is present.
newDst = &%s{} | ||
dst.%s = &%s{%s: newDst} | ||
} else { |
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.
At this point !srcTypeOk && !dstTypeOk
(which is the original check) - we empty the destination in order to make sure that it matches the source.
e2ffa70
to
e06448e
Compare
e06448e
to
067a979
Compare
067a979
to
3b7b7f9
Compare
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'm not completely sure about this one. If I want to change the type of the oneof
, I should replace the entire thing. Changing a subfield of the wrong "branch" should result in an error. Replacing the thing should only happen if the field mask contains (exactly) the oneof field itself, or (exactly) one of its "branches".
Just to make sure that I understood this: partial patches (so the ones which do have subfields) should require that the source and destination types match, but full replaces may change the type freely ? I understand the reasoning to a certain extent but keep in mind that the client does not know what is stored on the server side - It is hard to know when I need to do a replace and when I need to do a patch as a client, so requiring that I use the top level field complicates things. We require that the client fully retrieves the entity before the update if we require that the top level field is used, which is inconsistent with the rest of the API design. Note that this PR does not allow you to provide two |
Exactly. And to give a clear example, let's look at the
I think it's not unreasonable to expect that clients know the state of the entity (or at least the relevant fields) before they can make changes to those fields. |
I've implemented the requested change and added two test cases that should cover this. |
Summary
References TheThingsNetwork/lorawan-stack#5326
Changes
oneof
fields have the correct type, but instead behave as if they arenil
on mismatch.Notes for Reviewers
This is motivated by the ADR settings PR. Before this PR, it would be impossible to change the
oneof
field without clearing the field in between uses. This 'clear' operation (setting tonil
) was required because the generated code would complain that the source and the destinationoneof
type are mismatching.The effect on TTS can be seen at TheThingsNetwork/lorawan-stack@453b835