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

TypeError thrown with many=True on non-iterable types #906

Closed
tuukkamustonen opened this Issue Aug 8, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@tuukkamustonen
Contributor

tuukkamustonen commented Aug 8, 2018

With 3.0.0b13 this passes:

class Sch(Schema):
    foo = fields.Str()

for p in [False, 1, 1.2]:
    with pytest.raises(TypeError):
        Sch(many=True).load(p)

I think Schema.load() should rather catch invalid types and raise ValidationError?

@sloria

This comment has been minimized.

Member

sloria commented Aug 9, 2018

I think your suggestion makes sense, given that we raise a ValidationError for None

from marshmallow import Schema, fields

class Sch(Schema):
    foo = fields.Str()


Sch(many=True).load(None)
# marshmallow.exceptions.ValidationError: {'_schema': ['Invalid input type.']}

We should probably do the same for other non-iterable types. PRs welcome.

@sloria sloria added the help wanted label Aug 9, 2018

@sloria sloria added this to the 3.0 milestone Aug 9, 2018

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Aug 9, 2018

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Aug 9, 2018

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Aug 9, 2018

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Aug 30, 2018

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Aug 30, 2018

Fix marshmallow-code#930: Raise `ValidationError` on string with `man…
…y=True`

The actual fix actually came together in marshmallow-code#906, just adding tests and docs here.

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Aug 30, 2018

Fix marshmallow-code#930: Raise `ValidationError` on string with `man…
…y=True`

The actual fix actually came together in marshmallow-code#906, just adding tests and docs here.

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Sep 3, 2018

Fix marshmallow-code#930: Raise `ValidationError` on strings and mapp…
…ings with `many=True`

The actual fix actually came together in marshmallow-code#906, just expanding it to cover also
dicts, plus adding tests and docs here.

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Sep 3, 2018

Fix marshmallow-code#930: Raise `ValidationError` on strings and mapp…
…ings with `many=True`

The actual fix actually came together in marshmallow-code#906, just expanding it to cover also
dicts, plus adding tests and docs here.

tuukkamustonen added a commit to tuukkamustonen/marshmallow that referenced this issue Sep 3, 2018

Fix marshmallow-code#930: Raise `ValidationError` on strings and mapp…
…ings with `many=True`

The actual fix actually came together in marshmallow-code#906, just expanding it to cover also
dicts, plus adding tests and docs here.

@sloria sloria closed this in 02012d8 Sep 18, 2018

sloria added a commit that referenced this issue Sep 18, 2018

Merge pull request #954 from marshmallow-code/906-non-iterables-with-…
…many

Fixes for #906 (TypeError with many=True) and #907 (return [] not {} on many=True error) and #930 (disallows strings and dicts on many=True)

sloria added a commit that referenced this issue Sep 20, 2018

Prevent TypeError for non-collection with many=True
fixes #906
this is manual backport from #954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment