Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 does not work as schema key #62

Open
coding4food opened this issue Feb 28, 2019 · 3 comments
Open

0 does not work as schema key #62

coding4food opened this issue Feb 28, 2019 · 3 comments

Comments

@coding4food
Copy link

Suppose I want to map schemas like this:

class MySchema(OneOfSchema):
  type_schemas = {
    0: Schema1,
    1: Schema2
  }

When I try to load data with type 0, I get exception 'Missing data for required field.'.

@lafrech
Copy link
Member

lafrech commented Feb 28, 2019

Not sure that alone would solve your case but in those two lines:

https://github.com/marshmallow-code/marshmallow-oneofschema/blob/master/marshmallow_oneofschema/one_of_schema.py#L98

https://github.com/marshmallow-code/marshmallow-oneofschema/blob/master/marshmallow_oneofschema/one_of_schema.py#L174

if not type_schema:

could be replaced with

if type_schema is None:

Would you like to give it a try?

@coding4food
Copy link
Author

@lafrech the problem occurs during schema load.

@mm-arnvind
Copy link

👍 for the suggested solution, would also solve my use case with:

class MySchema(OneOfSchema):
    type_schemas = {
        True: Schema1,
        False: Schema2
    }

But I think this should be generalized to support None values as well, so we should consider using a sentinel like marshmallow.missing to mark that the value wasn't found

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

No branches or pull requests

3 participants