mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
There is a special case where message factories can be confused: if a module
written in C++ with pybind11 links against a self-recursive message, and that
message is part of another message loaded from Python, then the confusion
will happen.
Example:
# This one is also linked into the C++ module.
message SelfRecursive {
optional SelfRecursive self_recursive = 1;
}
# This one is used only in Python and not linked.
message OnlyUsedInPython {
optional SelfRecursive self_recursive = 2;
}
The caching through message_factory::RegisterMessageClass then happens on one
instance of the factory, but traversal with the lookup in another.
This occurs in the pure Python and upb implementations that have their own
default descriptor pools (and thus message factory).
Fix this by using the already passed message factory to registering the
message class to cache.
A test accounts for this case to avoid regressions.
PiperOrigin-RevId: 642551744
20 lines
554 B
Protocol Buffer
20 lines
554 B
Protocol Buffer
// Protocol Buffers - Google's data interchange format
|
|
// Copyright 2024 Google Inc. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file or at
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
syntax = "proto2";
|
|
|
|
package google.protobuf.python.internal;
|
|
|
|
import "google/protobuf/internal/self_recursive.proto";
|
|
|
|
message ContainsSelfRecursive {
|
|
optional SelfRecursive recursive = 1;
|
|
}
|
|
|
|
message ContainsIndirectRecursive {
|
|
optional IndirectRecursive recursive = 1;
|
|
}
|