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

body validation can not take effect when body is None #830

Open
guozhihua12 opened this issue Nov 15, 2019 · 1 comment
Open

body validation can not take effect when body is None #830

guozhihua12 opened this issue Nov 15, 2019 · 1 comment
Labels
need_repo Reproducable steps are needed to find and fix the described issue

Comments

@guozhihua12
Copy link

from marshmallow import Schema, fields

class TestingSchema(Schema):
a = fields.Integer(required=True)
b = fields.Integer(required=True)
c = fields.Integer()

@api.route.post('/test')
def test_validation(body: TestingSchema()):
return True, '', body

when body is None
image

@jay-tyler jay-tyler added the need_repo Reproducable steps are needed to find and fix the described issue label Feb 9, 2020
@jay-tyler
Copy link
Contributor

@guozhihua12 I'm having a little trouble reproducing this. Would you mind updating with the full code you're using for a repo? For instance, I'm not exactly sure how you are defining api and it doesn't seem to be something with direct documentation.

To try to reproduce, I used a file like this

from marshmallow import Schema, fields
import hug

class TestingSchema(Schema):
    a = fields.Integer(required=True)
    b = fields.Integer(required=True)
    c = fields.Integer()

@hug.route.post('/test')
def test_validation(body: TestingSchema()):
    return True, '', body

and then used POST requests like this

➜  hug-examples curl -X POST localhost:8000/test -d "a=1&b=2&c=3"
[true, "", {"b": 2, "a": 1, "c": 3}]
➜  hug-examples curl -X POST localhost:8000/test
{"errors": {"body": {"_schema": ["Invalid input type."]}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need_repo Reproducable steps are needed to find and fix the described issue
Projects
None yet
Development

No branches or pull requests

2 participants