marshmallow-code / marshmallow-code/marshmallow-oneofschema

Children schema doesn't get parent init values

Open
#86 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
142
Forks
44
Avg merge
7h 7m
Merged PRs (30d)
3

Description

When using a parent schema the initialization value do get passed to the actual children schema.
Use case: I want to be able to bypass the classic *post_load* `make_object` when I init a `partial` schema.
```python
@post_load
def make_object(self, data: Dict) -> object:
if self.__model__ is None or self.partial:
return data
return self.__model__(**data)
```
The problem is that if a use a parent `OneOfSchema` the final schema is instantiated withou any init parameters. See [here](https://github.com/marshmallow-code/marshmallow-oneofschema/blob/master/marshmallow_oneofschema/one_of_schema.py#L103) and [here](https://github.com/marshmallow-code/marshmallow-oneofschema/blob/master/marshmallow_oneofschema/one_of_schema.py#L172) in [marshmallowoneofschema/marshmallow_oneofschema/one_of_schema.py](https://github.com/marshmallow-code/marshmallow-oneofschema/blob/master/marshmallow_oneofschema/one_of_schema.py)
```python
schema = type_schema if isinstance(type_schema, Schema) else type_schema()
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in marshmallowoneofschema/marshmallow_oneofschema/one_of_schema.py at the linked schema-instantiation points around lines 103 and 172. Trace how a parent OneOfSchema selects and constructs the child schema, then verify that initialization values are preserved so partial schemas can bypass make_object as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.