marshmallow-code / marshmallow-code/marshmallow-oneofschema
Inconsistency of return type of OneOfSchema.load
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 142
- Forks
- 44
- Avg merge
- 7h 7m
- Merged PRs (30d)
- 3
Description
Hi there,
The current implementation of OneOfSchema.load is causing me errors downstream due to heterogeneity of the type of objects being returned.
My particular issue was due to how result is constructed when there's a ValdidationError for many==False (have a look here).
In the current implementation, result ends up being nested in a list [{"type": "foo"}] when there is a ValidationError (through the valid_data attribute), and equal to the input when where's no error.
Secondly result is constructed in a what appears to be an overly convoluted way where result gets set, then appended to a different variable that the overwrites the result....
I would gladly make a PR with a refactored version of OneOfSchema.load if that's allowed?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/marshmallow_oneofschema/one_of_schema.py around line 138 and trace how OneOfSchema.load constructs result for many=False, both with and without a ValidationError. The work is done when these paths return a consistent object type and the valid_data result is not unexpectedly nested in a list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100