Fix GetMutableMessagePointer() in python proto_api to find from generated factory before check with dynamic message factory

PiperOrigin-RevId: 693428774
pull/19137/head
Jie Luo 2 months ago committed by Copybara-Service
parent 09069f17dd
commit 3df01fa955
  1. 11
      python/google/protobuf/pyext/message_module.cc

@ -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());

Loading…
Cancel
Save