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

aiohttp parser breaks with more than one argument #165

Closed
ariddell opened this issue May 5, 2017 · 5 comments

Comments

@ariddell
Copy link

commented May 5, 2017

Nothing seems to work once I add more than one field. Here's my minimal example.

I'm validating with:

programs_actions_args = {
    'type': webargs.fields.Str(required=True),
    'chain': webargs.fields.Integer(required=True),
}

and here's what happens when I POST:

POST /v1/programs/8137474d19926b0aa8efd4f1d3944131d59269d97a7bd8dab8e79d667eb314df/actions HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 34
Content-Type: application/json
Host: localhost:8080
User-Agent: HTTPie/0.9.9

{
    "chain": "3",
    "type": "sampling"
}

HTTP/1.1 422 Unprocessable Entity
Content-Length: 46
Content-Type: application/json
Date: Fri, 05 May 2017 21:20:42 GMT
Server: Python/3.6 aiohttp/2.0.7

{
    "type": [
        "Missing data for required field."
    ]
}

Things work fine if there's only one argument.

@ariddell

This comment has been minimized.

Copy link
Author

commented May 5, 2017

Things seem to work fine if I just use Marshmallow directly.

@sloria

This comment has been minimized.

Copy link
Member

commented May 12, 2017

Thanks @ariddell for reporting this. I'll try to look at this over the next few days. I'd gladly review and merge a PR fixing this. =)

@ariddell

This comment has been minimized.

Copy link
Author

commented May 12, 2017

I wish I knew more about marshmallow and aiohttp internals. I'll probably take a stab at it eventually. Thanks for webargs (and everything else)!

@zaro

This comment has been minimized.

Copy link
Contributor

commented May 15, 2017

Same here.

After quite some digging, found out that in

    def parse_json(self, req, name, field):
        """Pull a json value from the request."""
        if not (req.has_body and is_json_request(req)):
            return core.missing
        json_data = self._cache.get('json')
        if json_data is None:
            self._cache['json'] = json_data = yield from req.json()
        return core.get_value(json_data, name, field, allow_many_nested=True)

req.has_body is true only on the first invocation, and false for the rest. In my case it's 3 arguments and only the first one gets parsed, in the following two it is false, and the parameter is considered missing.

zaro added a commit to zaro/webargs that referenced this issue May 15, 2017

@zaro zaro referenced this issue May 15, 2017

zaro added a commit to zaro/webargs that referenced this issue May 16, 2017

@sloria sloria closed this in #166 May 16, 2017

sloria added a commit that referenced this issue May 16, 2017

@sloria

This comment has been minimized.

Copy link
Member

commented May 17, 2017

Just FYI: The latest release (1.6.2) includes the fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.