Skip to content

[Bug] validate should check passed in model type #257

@Pirulax

Description

@Pirulax

Describe the bug
The validate function should check the type of the passed in schema.
In my case doing this:

import sanic as s
from sanic_ext import validate

class MyRESTMethodArgs:
    id : str
@bp.post('/create')
@validate(json=MyRESTMethodArgs)
async def post_create(req : s.Request, body : MyRESTMethodArgs):
    pass # Business logic

Fails miserably with:

File "<irrelevant>\.venv\Lib\site-packages\sanic_ext\extras\validation\decorator.py", line 73, in decorated_function
    retval = f(*args, **kwargs)

Inspecting it closer, it turns out schemas looks like this:

{'json': {}, 'form': None, 'query': None}

I assume the issue is with generate_schema for some reason just returning {} instead of raising an exception

To Reproduce
See above

Expected behavior
validate should fail if it encounters a schema model it can't process (As according to the docs, a simple Python class can't be used)

Environment (please complete the following information):
mode: debug, single worker
server: sanic, HTTP/1.1
python: 3.12.4
platform: Windows-11-10.0.22631-SP0
packages: sanic-routing==23.12.0, sanic-ext==23.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions