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 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b10a4ea5 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b10a4ea5 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b10a4ea5 Branch: refs/heads/master Commit: b10a4ea59231d134662d49417add2ccd7779cde7 Parents: 772c8f5 Author: Qian Zhang <[email protected]> Authored: Tue Jul 25 23:03:43 2017 +0800 Committer: Qian Zhang <[email protected]> Committed: Tue Oct 3 08:53:11 2017 +0800 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/protobuf.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/b10a4ea5/3rdparty/stout/include/stout/protobuf.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/stout/include/stout/protobuf.hpp index 15690b6..baad126 100644 --- a/3rdparty/stout/include/stout/protobuf.hpp +++ b/3rdparty/stout/include/stout/protobuf.hpp @@ -451,7 +451,19 @@ struct Parser : boost::static_visitor<Try<Nothing>> field->enum_type()->FindValueByName(string.value); if (descriptor == nullptr) { - return Error("Failed to find enum for '" + string.value + "'"); + if (field->is_required()) { + return Error("Failed to find enum for '" + string.value + "'"); + } + + // Unrecognized enum value will be discarded if this is not a + // required enum field, which makes the field's `has..` accessor + // return false and its getter return the first value listed in + // the enum definition, or the default value if one is specified. + // + // This is the deserialization behavior of proto2, see the link + // below for details: + // https://developers.google.com/protocol-buffers/docs/proto#updating + break; } if (field->is_repeated()) {
