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

Union field #1191

Closed
Ovyerus opened this issue Apr 8, 2019 · 3 comments
Closed

Union field #1191

Ovyerus opened this issue Apr 8, 2019 · 3 comments

Comments

@Ovyerus
Copy link

Ovyerus commented Apr 8, 2019

Can't seem to find this anywhere, but a field that allows an incoming value to be matched across several different types/fields would be pretty handy.

Example could be something like this:

fields.Union([fields.Str(validate=validate.Length(max=20)), fields.Int()])

Where if it failed to validate against the first field, it'd go through the rest of the fields provided until it finds one it matches, otherwise raising an error.

@Ovyerus Ovyerus changed the title Field for allowing multiple types Union field Apr 8, 2019
@sloria
Copy link
Member

sloria commented Apr 8, 2019

There isn't a built-in union field at the moment, and we don't have plans to add one in the near future. Since we won't get to this soon, I'm going to close this issue for now.

If you end up developing this as a separate package, please comment here and add it to the wiki: https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem

@sloria sloria closed this as completed Apr 8, 2019
@adamboche
Copy link

Here's an implementation. https://github.com/adamboche/python-marshmallow-union
I've added a link in the wiki as suggested.

@smith-kyle
Copy link

What's the recommended way of implementing this with marshmallow? validate?

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

4 participants