sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation with Dataclasses| About Optional[str] and None

scriptkitz opened this issue · comments

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

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.

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