Skip to content

fix(schema): decode nested Array and Map records as Record objects - #322

Open
dragonknightk wants to merge 1 commit into
apache:mainfrom
dragonknightk:fix/172
Open

dragonknightk wants to merge 1 commit into
apache:mainfrom
dragonknightk:fix/172

Conversation

@dragonknightk

Copy link
Copy Markdown

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.

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>
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.

[Bug] Nested arrays decoding not working as expected

1 participant