Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/values/struct_value_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,19 @@ class MessageValueBuilderImpl {
if (error_value) {
return false;
}
if (map_value_field->cpp_type() ==
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE &&
entry_value.IsNull()) {
auto well_known_type =
map_value_field->message_type()->well_known_type();
if (well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_ANY &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE &&
well_known_type !=
google::protobuf::Descriptor::WELLKNOWNTYPE_LISTVALUE &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_STRUCT) {
return true;
}
}
google::protobuf::MapValueRef proto_value;
extensions::protobuf_internal::InsertOrLookupMapValue(
*reflection_, message_, *field, proto_key, &proto_value);
Expand Down Expand Up @@ -989,6 +1002,16 @@ class MessageValueBuilderImpl {
CEL_RETURN_IF_ERROR(list_value->ForEach(
[this, field, accessor,
&error_value](const Value& element) -> absl::StatusOr<bool> {
if (field->message_type() != nullptr && element.IsNull()) {
auto well_known_type = field->message_type()->well_known_type();
if (well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_ANY &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE &&
well_known_type !=
google::protobuf::Descriptor::WELLKNOWNTYPE_LISTVALUE &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_STRUCT) {
return true;
}
}
CEL_ASSIGN_OR_RETURN(error_value,
(*accessor)(descriptor_pool_, message_factory_,
&well_known_types_, reflection_,
Expand Down
6 changes: 0 additions & 6 deletions conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,6 @@ _TESTS_TO_SKIP = [
"conversions/string/double_hard",

# Recent changes
"proto2/set_null/map_timestamp_null_pruned",
"proto2/set_null/map_duration_null_pruned",
"proto2/set_null/map_wrapper_null_pruned",
"proto3/set_null/map_timestamp_null_pruned",
"proto3/set_null/map_duration_null_pruned",
"proto3/set_null/map_wrapper_null_pruned",
"string_ext/format/default precision for fixed-point clause with int",
"string_ext/format/default precision for fixed-point clause with uint",
"string_ext/format/default precision for scientific notation with int",
Expand Down
16 changes: 16 additions & 0 deletions eval/public/structs/proto_message_type_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,29 @@ absl::Status ProtoMessageTypeAdapter::SetField(
ValidateSetFieldOp(value_field_descriptor != nullptr, field->name(),
"failed to find value field descriptor"));

bool prune_when_null = false;
if (value_field_descriptor->cpp_type() ==
google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
auto well_known_type =
value_field_descriptor->message_type()->well_known_type();
if (well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_ANY &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_LISTVALUE &&
well_known_type != google::protobuf::Descriptor::WELLKNOWNTYPE_STRUCT) {
prune_when_null = true;
}
}

CEL_ASSIGN_OR_RETURN(const CelList* key_list, cel_map->ListKeys(arena));
for (int i = 0; i < key_list->size(); i++) {
CelValue key = (*key_list).Get(arena, i);

auto value = (*cel_map).Get(arena, key);
CEL_RETURN_IF_ERROR(ValidateSetFieldOp(value.has_value(), field->name(),
"error serializing CelMap"));
if (prune_when_null && value->IsNull()) {
continue;
}
Message* entry_msg = message->GetReflection()->AddMessage(message, field);
CEL_RETURN_IF_ERROR(internal::SetValueToSingleField(
key, key_field_descriptor, entry_msg, arena));
Expand Down