pybind / pybind11_protobuf

Pybind11 bindings for Google's Protocol Buffers
Other
57 stars 35 forks source link

Raise "Proto Message has an Unknown Field" in certain situations. #86

Closed copybara-service[bot] closed 2 years ago

copybara-service[bot] commented 2 years ago

Raise "Proto Message has an Unknown Field" in certain situations.

The motivation for this change is to flag accidental loss of protobuf extensions when use_fast_cpp_protos is in use, to turn silent but potentially critical failures into noisy failures, for example:

Proto Message of type pybind11.test.NestRepeated has an Unknown Field with
parent of type pybind11.test.BaseMessage: base_msgs.1003
(pybind11_protobuf/tests/extension_nest_repeated.proto,
pybind11_protobuf/tests/extension.proto).
Please add the required `cc_proto_library` `deps`.
Only if there is no alternative to suppressing this error, use
`pybind11_protobuf::AllowUnknownFieldsFor("pybind11.test.NestRepeated", "base_msgs");`
(Warning: suppressions may mask critical bugs.)

See the updated "Protobuf Extensions" section in README.md for background and details.

check_unknown_fields.cc is mostly the work of @laramiel, with an initial implementation only by @rwgk.

MessageMayContainExtensionsMemoized() is for speed-up, but note that it also limits the scope of the Unknown Field detection (as explained in the updated README.md section).