Repository navigation
fix(schema): decode nested Array and Map records as Record objects - #322
Open
dragonknightk wants to merge 1 commit into
Open
dragonknightk wants to merge 1 commit into
dragonknightk wants to merge 1 commit into
Conversation
Closes issue 172 ### Motivation Decoding a Record with Array(Array(Record)) leaves the inner values as dicts, so decoded.b[0][0].a raises AttributeError. This happens because Record.__init__ only handles the first level, and both JsonSchema.decode and AvroSchema.decode go through this path. ### Modifications Record.__init__ now walks Array and Map fields recursively and turns any dict that matches a Record field into a Record, at any depth. The same fix also covers nested Map combinations (Map of Map, Array of Map, Map of Array). There are no C++ binding changes. ### Verifying this change Added JsonSchema decode tests for the issue 172 reproduction (Array of Array of Record) and for the nested Map combinations above. The tests check that the inner value is a Record and that its field is readable, plus a JSON encode/decode round-trip for the array case. Existing one-level Array(Record) and Map(Record) JSON and Avro encode/decode tests still cover the previous behavior. Signed-off-by: dragonknightk <37928252+dragonknightk@users.noreply.github.com>
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.
Fixes #172
Motivation
Decoding a Record with Array(Array(Record)) leaves the inner values as dicts, so decoded.b[0][0].a raises AttributeError. This happens because Record.init only handles the first level, and both JsonSchema.decode and AvroSchema.decode go through this path.
Modifications
Record.init now walks Array and Map fields recursively and turns any dict that matches a Record field into a Record, at any depth. The same fix also covers nested Map combinations (Map of Map, Array of Map, Map of Array).
There are no C++ binding changes.
Verifying this change
Added JsonSchema decode tests for the issue 172 reproduction (Array of Array of Record) and for the nested Map combinations above. The tests check that the inner value is a Record and that its field is readable, plus a JSON encode/decode round-trip for the array case. Existing one-level Array(Record) and Map(Record) JSON and Avro encode/decode tests still cover the previous behavior.
AI Disclosure
Human-led contribution. Grok Bot, working for dragonknightk, assisted with this change, including the code, tests, and description. All submitted content was reviewed by a human before submission.