[
https://issues.apache.org/jira/browse/MESOS-7828?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16189162#comment-16189162
]
Qian Zhang commented on MESOS-7828:
-----------------------------------
commit 2f3ceb45106e79586f2c32bfd26db0318d608075
Author: Qian Zhang [email protected]
Date: Thu Jul 27 16:15:44 2017 +0800
Added a test `ProtobufTest.ParseJSONUnrecognizedEnum`.
Review: https://reviews.apache.org/r/61174
3rdparty/stout/tests/protobuf_tests.cpp | 33 +++++++++++++++++++++++++++++++++
3rdparty/stout/tests/protobuf_tests.proto | 9 +++++++++
2 files changed, 42 insertions(+)
commit b10a4ea59231d134662d49417add2ccd7779cde7
Author: Qian Zhang <[email protected]>
Date: Tue Jul 25 23:03:43 2017 +0800
Fixed JSON protobuf deserialization to ignore unrecognized enum values.
Protobuf deserialization will discard any unrecognized enum values.
This patch fixes our custom JSON -> protobuf conversion code to be
consistent with this behavior.
See MESOS-4997 for why this matters when dealing with upgrades.
Fixes MESOS-7828.
Review: https://reviews.apache.org/r/61109
3rdparty/stout/include/stout/protobuf.hpp | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
> Current approach to parse protobuf enum from JSON does not support upgrades
> ---------------------------------------------------------------------------
>
> Key: MESOS-7828
> URL: https://issues.apache.org/jira/browse/MESOS-7828
> Project: Mesos
> Issue Type: Bug
> Reporter: Qian Zhang
> Assignee: Qian Zhang
>
> To use protobuf enum in a backwards compatible way, [the suggestion on the
> protobuf mailing
> list|https://groups.google.com/forum/#!msg/protobuf/NhUjBfDyGmY/pf294zMi2bIJ]
> is to use optional enum fields and include an UNKNOWN value as the first
> entry in the enum list (and/or explicitly specifying it as the default). This
> can handle the case of parsing protobuf message from a serialized string, but
> it can not handle the case of parsing protobuf message from JSON.
> E.g., when I access master endpoint with an inexistent enum {{xxx}}, I will
> get an error:
> {code}
> $ curl -X POST -H "Content-Type: application/json" -d '{"type": "xxx"}'
> 127.0.0.1:5050/api/v1
> Failed to convert JSON into Call protobuf: Failed to find enum for 'xxx'%
> {code}
> In the {{Call}} protobuf message, the enum {{Type}} already has a default
> value {{UNKNOWN}} (see
> [here|https://github.com/apache/mesos/blob/1.3.0/include/mesos/v1/master/master.proto#L45]
> for details) and the field {{Call.type}} is optional, but the above curl
> command will still fail. The root cause is, in the code
> [here|https://github.com/apache/mesos/blob/1.3.0/3rdparty/stout/include/stout/protobuf.hpp#L449:L454]
> when we try to get the enum value for the string "xxx", it will fail since
> there is no any enum value corresponding to "xxx".
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)