Skip to content

descriptor: ignore unknown enum names when a JSON parse ignores unknown fields - #846

Closed
hamza-paracha wants to merge 1 commit into
anthropics:mainfrom
hamza-paracha:devin/1795207277-reflect-json-unknown-enum
Closed

hamza-paracha wants to merge 1 commit into
anthropics:mainfrom
hamza-paracha:devin/1795207277-reflect-json-unknown-enum

Conversation

@hamza-paracha

Copy link
Copy Markdown

Summary

DynamicMessage::from_json_ignoring_unknown (DynamicMessageSeed::ignore_unknown_fields(true)) discards unknown field names, but an enum name the enum does not declare was still a parse error:

// reflect_test.proto: Containers { Color color = 6; repeated Color colors = 7; }
DynamicMessage::from_json_ignoring_unknown(pool, idx, r#"{"color": "PURPLE"}"#)
// Err: invalid value: string "PURPLE", expected a known enum variant name

Generated code with JsonParseOptions::ignore_unknown_enum_values accepts this, and so does protobuf C++, whose ignore_unknown_fields also covers unknown enum names. The conformance runner's reflection mode (BUFFA_VIA_REFLECT=1) parses JSON_IGNORE_UNKNOWN_PARSING_TEST requests through this function and fails the ten Recommended.{Proto2,Proto3}.JsonInput.IgnoreUnknownEnumStringValue{InOptionalField,InRepeatedField,InMapValue,InRepeatedPart,InMapPart} tests. CI does not catch it because run-conformance.sh does not pass --enforce_recommended.

With the flag set, an unknown name is now ignored the same way the generated path ignores it:

Field kind Result
singular left unset
repeated element dropped, the others kept
map entry dropped

deserialize_enum now returns a three-state EnumJson { Value, Null, Unknown } instead of Option<Value>, so the list and map visitors can tell an ignored element apart from null. A null element or map value is still an error. Strict parsing is unchanged, and an unknown number for a closed enum is still an error in both modes. The ignore_unknown_fields rustdoc and the buffa::json module doc that said an unknown enum name is always a parse error for DynamicMessage are updated.

Testing

  • buffa-descriptor/tests/json_e2e.rs: json_lenient_mode_ignores_unknown_enum_names covers the singular and repeated cases and a null element. It fails on main and passes here.
  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass.
  • Conformance (protobuf v33.5 runner, --enforce_recommended, BUFFA_VIA_REFLECT=1): main has 2783 successes and 10 failures (the tests above). This branch has 2793 successes and 0 failures.

…wn fields

DynamicMessage::from_json_ignoring_unknown discarded unknown field names
but still failed on an enum name the enum does not declare. Generated code
with JsonParseOptions::ignore_unknown_enum_values and protobuf C++ with
ignore_unknown_fields both accept it, and the reflection conformance run
fails the ten Recommended IgnoreUnknownEnumStringValue* tests.

With the flag set, an unknown name now leaves a singular field unset and
drops the element of a repeated field or the entry of a map. A null
element and an unknown closed-enum number are still errors.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 19:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
✅ hamza-paracha
❌ @devin-ai-integration[bot]
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants