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

[Bug] @validate decorator doesn't work for Class-Based Views #2483 #92

Closed
adamcohenhillel opened this issue Jun 21, 2022 · 1 comment
Closed

Comments

@adamcohenhillel
Copy link
Contributor

Describe the bug
While using the @validate decorator on a class-based view, I get the following exception:

[...]python/site-packages/sanic_ext/extras/validation/decorator.py", line 39, in decorated_function
    data=request.json,
AttributeError: 'SomeResource' object has no attribute 'json'

And this is how my Class Based view look like:

class SomeResource(HTTPMethodView):
    @validate(json=ResourceSchema)
    async def post(self, request):
        pass

Additional Notes
Diving quickly into the code of the decorator, it seems like we are not handling the class case of the views, where the first argument of the method is the class instance and not the request instance (like in the function-based view):

async def decorated_function(request: Request, *args, **kwargs):

I think a solution for that can be to use the kwargs rather than the position, but I am not too familiar with the codebase just yet, so there might be a more suitable solution for this repo.

@ahopkins
Copy link
Member

Thanks, for jumping on this.

ahopkins added a commit that referenced this issue Jun 29, 2022
…#93)

Co-authored-by: Adam Cohen Hillel <adamcohenhillel@gmail.com>
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants