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

AioHTTPParser does not works with multiple `@use_args` at same handler #273

Closed
dnp1 opened this issue Aug 15, 2018 · 5 comments

Comments

@dnp1
Copy link

commented Aug 15, 2018

According to the docs, we can use the decorator twice.

https://webargs.readthedocs.io/en/latest/advanced.html#mixing-locations
However, use @use_args decorator twice leads to an error when the first schema is valid:
assert isinstance(req, web.Request), "Request argument not found for handler"
AssertionError: Request argument not found for handler

@dnp1 dnp1 changed the title AioHTTP parser does'nt works with multiple `@use_args` AioHTTPParser does'nt works with multiple `@use_args` Aug 15, 2018

@dnp1 dnp1 changed the title AioHTTPParser does'nt works with multiple `@use_args` AioHTTPParser does'nt [[works with multiple `@use_args` Aug 15, 2018

@dnp1 dnp1 changed the title AioHTTPParser does'nt [[works with multiple `@use_args` AioHTTPParser does not works with multiple `@use_args` Aug 15, 2018

@dnp1 dnp1 changed the title AioHTTPParser does not works with multiple `@use_args` AioHTTPParser does not works with multiple `@use_args` at same handler Aug 15, 2018

@sloria

This comment has been minimized.

Copy link
Member

commented Aug 19, 2018

@dnp1 Can you please post code to reproduce the issue?

@jangelo

This comment has been minimized.

Copy link

commented Oct 18, 2018

@sloria I ran into this issue as well. Here is some code to reproduce. Ultimately, I'm trying to use a schema to define the json body and also access the path parameter. If you know of another way to do this, I'd appreciate any insight. Thanks.

from aiohttp import web
from marshmallow import Schema, fields
from webargs.aiohttpparser import use_args


class UserSchema(Schema):
    name = fields.String()
    age = fields.Integer()


user_schema = UserSchema()


@use_args({"id": fields.Integer(required=True, location="match_info")})
@use_args(user_schema, locations=("json",))
async def get_user(request, args):
    id = args['id']
    name = args['name']
    age = args['age']
    text = "Hello, " + name
    return web.Response(text=text)

app = web.Application()
app.add_routes([web.post('/user/{id:\d+}', get_user)])

web.run_app(app)


# Sample curl
# curl -d '{"name":"Joe", "age":"50"}' -H "Content-Type: application/json" -X POST http://0.0.0.0:8080/user/1
#
# Requirements.txt
# aiohttp==3.4.4
# webargs==4.1.0
#
# pip install -U marshmallow --pre
@sloria

This comment has been minimized.

Copy link
Member

commented Oct 18, 2018

OK, thanks @jangelo . I haven't tried using use_args multiple times for the same view. I'm not even sure if it's an aiohttpparser-specific issue.

I would certainly review and merge a PR fixing this. Even an analysis of the problem would be much appreciated.

@jangelo

This comment has been minimized.

Copy link

commented Nov 22, 2018

Sorry it took long. Here is a PR with a fix. Thanks.
#326

@sloria

This comment has been minimized.

Copy link
Member

commented Dec 16, 2018

This was fixed by #326 and released in 4.1.3.

@sloria sloria closed this Dec 16, 2018

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.