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

Validation with Dataclasses| About Optional[str] and None #2794

Open
1 task done
scriptkitz opened this issue Jul 19, 2023 · 2 comments · May be fixed by sanic-org/sanic-ext#251
Open
1 task done

Validation with Dataclasses| About Optional[str] and None #2794

scriptkitz opened this issue Jul 19, 2023 · 2 comments · May be fixed by sanic-org/sanic-ext#251
Assignees
Labels

Comments

@scriptkitz
Copy link

scriptkitz commented Jul 19, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

from typing import Optional

@dataclass
class VClass:
    name: Optional[str] = None
    num: Optional[int] = None

@app.route("/")
@validate(form=VClass)
def test(req, body):
    print(body.name, type(body.name))
    print(body.num, type(body.num))

curl http://localhost/

-----------RESULT---------------
None <class 'str'>
None <class 'NoneType'>


The value of body.name is the string "None" , not a NoneType.
Is this a bug?

Code snippet

No response

Expected Behavior

No response

How do you run Sanic?

As a script (app.run or Sanic.serve)

Operating System

Windows

Sanic Version

v23.3.0

Additional context

No response

@scriptkitz scriptkitz added the bug label Jul 19, 2023
@ChihweiLHBird
Copy link
Member

ChihweiLHBird commented Nov 26, 2023

I confirm this issue is reproduceable. If no one else had started working on this, I will look into it.
But this looks like a sanic extension issue.

@ChihweiLHBird ChihweiLHBird self-assigned this Nov 26, 2023
@ChihweiLHBird
Copy link
Member

ChihweiLHBird commented Nov 26, 2023

@sanic-org/sanic-release-managers
Can we transfer this issue to sanic-ext repo?

@ChihweiLHBird ChihweiLHBird linked a pull request Jun 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants