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

Fix issue #92 - @validate decorator not working for class-based views #93

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions sanic_ext/extras/validation/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sanic import Request

from sanic_ext.exceptions import InitError
from sanic.exceptions import SanicException

from .setup import do_validation, generate_schema

Expand All @@ -31,7 +32,14 @@ def validate(

def decorator(f):
@wraps(f)
async def decorated_function(request: Request, *args, **kwargs):
async def decorated_function(*args, **kwargs):

if args and type(args[0]) == Request:
adamcohenhillel marked this conversation as resolved.
Show resolved Hide resolved
request: Request = args[0]
elif len(args) > 1:
request: Request = args[1]
else:
raise SanicException('Request could not be found')

if schemas["json"]:
await do_validation(
Expand Down Expand Up @@ -66,7 +74,7 @@ async def decorated_function(request: Request, *args, **kwargs):
allow_multiple=True,
allow_coerce=True,
)
retval = f(request, *args, **kwargs)
retval = f(*args, **kwargs)
if isawaitable(retval):
retval = await retval
return retval
Expand Down