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

Nullable fields on Tortoise model are required in create route #99

Open
rgreen32 opened this issue Sep 15, 2021 · 1 comment
Open

Nullable fields on Tortoise model are required in create route #99

rgreen32 opened this issue Sep 15, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@rgreen32
Copy link

Hello!, I have simple model with a nullable field:

from tortoise import fields, models

class Scan(models.Model):
    id = fields.IntField(pk=True)
    scan_data = fields.JSONField()
    time_stamp = fields.DatetimeField(auto_now=True, null=True)  
    class Meta:
        table = "scans"

router = TortoiseCRUDRouter(
    schema=models.Scan_Pydantic, 
    db_model=models.Scan
}

If I send some data to the post route, I expect that the "time_stamp" field will not need to be present in the payload because it is declared as nullable.

{
    "carrier": "FEDEX",
    "scan_data": {"scan_code":  "CD",  "scan_description":  "DELAY"}
}

but instead this fails with a 422 saying the "time_stamp" field is required.

I understand that adding the field with a null value work but I feel like declaring the field as nullable on model should make the field optional entirely in body of create requests.

I'd be happy to submit a pr for this change if there is support for it ! :)

@awtkns awtkns added the enhancement New feature or request label Sep 15, 2021
@awtkns
Copy link
Owner

awtkns commented Sep 15, 2021

If you want to PR this you totally can. If not, I would be happy to pick up the implementation sometime in the future. This is somewhat related to #73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants