Skip to content

Fix KeyError in _EncodeCustomFieldNames when field name is a substring - #336

Merged
YonathanZetune merged 1 commit into
masterfrom
fix-custom-field-remapping-keyerror
Sep 17, 2026
Merged

YonathanZetune merged 1 commit into
masterfrom
fix-custom-field-remapping-keyerror

Conversation

@YonathanZetune

Copy link
Copy Markdown
Contributor

Problem

_EncodeCustomFieldNames previously checked if python_name in encoded_value: (substring membership in the raw serialized JSON str) instead of checking key membership in decoded_value (dict).

When a message has custom JSON field mappings registered via AddCustomJsonFieldMapping and an unset field's python_name appears as a substring of either:

  1. Another populated field name (e.g., service_directory_name vs. metadata_service_directory_name), or
  2. Any string field value in the JSON payload,

python_name in encoded_value evaluates to True, causing decoded_value.pop(python_name) to raise a KeyError.

Solution

Check if python_name in decoded_value: so key membership is verified against the decoded dictionary, matching _DecodeCustomFieldNames. Added unit test coverage for both field-name and field-value substring collisions.

@YonathanZetune
YonathanZetune merged commit 32f9650 into master Sep 17, 2026
8 checks passed
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