fix(python): preserve original JSON keys in Data shim round-trips#1900
Open
syf2211 wants to merge 1 commit into
Open
fix(python): preserve original JSON keys in Data shim round-trips#1900syf2211 wants to merge 1 commit into
syf2211 wants to merge 1 commit into
Conversation
Fixes github#1138 The Data compatibility shim converted JSON keys to snake_case for attribute access but could not reconstruct abbreviation-heavy camelCase keys (userURL, sessionID, OAuthToken) on to_dict(). Store the original JSON key per field during from_dict() and prefer it when serializing back. Includes regression tests for the abbreviation key cases described in the issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
Data.from_dict().to_dict()corrupting JSON keys that contain common abbreviations (e.g.userURL,sessionID,OAuthToken).Motivation
The
Datacompatibility shim converts inbound JSON keys to snake_case for attribute access, then uses heuristic_compat_to_json_keywhen serializing back. That converter cannot reconstruct abbreviation-heavy camelCase, so keys were mutated on round-trip. This breaks consumers of unknown/custom event payloads that log, cache, or echo events.Fixes #1138
Changes
Data._json_keysduringfrom_dict()to_dict(); fall back to_compat_to_json_keyfor manually constructedData(**kwargs)scripts/codegen/python.tsand regeneratesession_events.pyTests
uv run pytest test_event_forward_compatibility.py -v— 11 passeduv run ruff check test_event_forward_compatibility.py— passedtest_data_shim_preserves_abbreviation_json_keys_on_round_tripcovering the keys cited in the issueNotes
SessionEvent.from_dictalready useRawSessionEventData(verbatim raw). This fix targets theDatashim used for backward-compatible/manual payloads.userURLvsuserUrlboth mapping touser_url) is unchanged.