Fixed a bug when deep copying a map field with a closed enum value.

PiperOrigin-RevId: 601195914
pull/15570/head
Joshua Haberman 10 months ago committed by Copybara-Service
parent 21eb4e9350
commit ca5ca62fa6
  1. 6
      python/google/protobuf/internal/message_test.py
  2. 5
      upb/message/copy.c

@ -1406,6 +1406,12 @@ class Proto2Test(unittest.TestCase):
with self.assertRaises(ValueError):
m.unknown_map_field[1] = 123
def testDeepCopyClosedEnum(self):
m = map_proto2_unittest_pb2.TestEnumMap()
m.known_map_field[123] = 0
m2 = copy.deepcopy(m)
self.assertEqual(m, m2)
def testExtensionsErrors(self):
msg = unittest_pb2.TestAllTypes()
self.assertRaises(AttributeError, getattr, msg, 'Extensions')

@ -98,7 +98,7 @@ upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type,
const upb_MiniTableField* value_field =
&map_entry_table->UPB_PRIVATE(fields)[1];
const upb_MiniTable* value_sub =
(value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub)
upb_MiniTableField_CType(value_field) == kUpb_CType_Message
? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field)
: NULL;
upb_CType value_field_type = upb_MiniTableField_CType(value_field);
@ -165,8 +165,7 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array,
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field);
upb_Array* cloned_array = upb_Array_DeepClone(
array, upb_MiniTableField_CType(field),
upb_MiniTableField_CType(field) == kUpb_CType_Message &&
field->UPB_PRIVATE(submsg_index) != kUpb_NoSub
upb_MiniTableField_CType(field) == kUpb_CType_Message
? upb_MiniTable_GetSubMessageTable(mini_table, field)
: NULL,
arena);

Loading…
Cancel
Save