marshmallow-code / marshmallow-code/marshmallow-oneofschema

It's hard to use a parent schema's data to control a Nested OneOfSchema

Open
#214 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
142
Forks
44
Avg merge
7h 7m
Merged PRs (30d)
3

Description

I have a schema that uses `fields.Nested` on a `OneOfSchema` type schema, where the `type` field data comes from the parent. I can work around the lack of built-in way to do that with some context, and override `get_obj_type` / `get_data_type`.

The new way of doing context in Marshmallow v4 has turned this into a much harder endeavour. I've had to override the `load` method in the parent schema so I can set a contextvar once per item in the incoming list of data which is now picked up by the nested schema's `get_xxx` methods.

I'm not really sure if there's any easier way to do it but leaving this Issue here in case someone has already thought about it.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing fields.Nested and OneOfSchema, especially get_obj_type and get_data_type, alongside Marshmallow v4 context handling. Reproduce the parent-derived type case for nested items and compare it with the current contextvar and parent load overrides. Done should mean the parent schema can control the nested OneOfSchema through a supported, documented approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.