Replies: 3 comments 3 replies
-
I believe golang just appends: https://github.com/protocolbuffers/protobuf-go/blob/de9682ad1656cd1ee6808865f7a42f5a5d79eb73/proto/merge.go#L104 |
Beta Was this translation helpful? Give feedback.
-
Good catch, @jcready. I missed this discussion initially, sorry. The partial merge is a logic specific to protobuf-ts. It is definitely different from the protobuf merge semantics, where repeated fields (including maps) are appended, which I think is pretty unexpected for JS developers. The JSDoc states:
Looking at the code, that doesn't seem to be the case for repeated message fields and neither for maps. The values of the input array or map replace the corresponding values in the output array or map. But the map or array itself is not replaced, and entries may remain in the output. I find it difficult to reason about the semantics - there are always arguments in favor and against a specific behavior. But the difference between documentation and implementation is clearly a bug. |
Beta Was this translation helpful? Give feedback.
-
@timostamm What's your take on #335? Have you had time to consider merging it? |
Beta Was this translation helpful? Give feedback.
-
I can't tell if this is intentional or perhaps I'm just not reading the code correctly, but there doesn't appear to be a test case for it so I figured I'd ask.
protobuf-ts/packages/runtime/src/reflection-merge-partial.ts
Lines 60 to 64 in 80de3ee
With the above logic it seems like if the
target
/output
array was longer than thesource
/input
array then we would end up with with only a partially overwrittentarget
/output
array.The logic for handling repeated scalar fields just replaces the
target
array which is why I suspect that this behavior isn't expected.Beta Was this translation helpful? Give feedback.
All reactions