Skip to content

Commit

Permalink
Fix GetMutableMessagePointer() in python proto_api to find from gener…
Browse files Browse the repository at this point in the history
…ated factory before check with dynamic message factory

PiperOrigin-RevId: 693428774
  • Loading branch information
anandolee authored and copybara-github committed Nov 5, 2024
1 parent 09069f1 commit 3df01fa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/google/protobuf/pyext/message_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ struct ApiImplementation : google::protobuf::python::PyProto_API {
if (pyfile == nullptr) {
return absl::InvalidArgumentError("DESCRIPTOR has no attribute 'file'");
}
auto gen_d =
google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName(
descriptor_full_name);
if (gen_d) {
Py_DECREF(pyfile);
Py_DECREF(fn);
google::protobuf::Message* msg = google::protobuf::MessageFactory::generated_factory()
->GetPrototype(gen_d)
->New();
return CreatePythonMessageMutator(msg, msg, py_msg);
}
auto d = FindMessageDescriptor(pyfile, descriptor_full_name);
Py_DECREF(pyfile);
RETURN_IF_ERROR(d.status());
Expand Down

0 comments on commit 3df01fa

Please sign in to comment.