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] ModelSchema does not validate Blank fields properly #882

Open
jam13 opened this issue Oct 18, 2023 · 1 comment
Open

[BUG] ModelSchema does not validate Blank fields properly #882

jam13 opened this issue Oct 18, 2023 · 1 comment

Comments

@jam13
Copy link

jam13 commented Oct 18, 2023

Describe the bug
Given a model field:

description = models.TextField(blank=True)

ModelSchema treats it as an optional field (which is I guess correct), but doesn't default it to an empty string. This results in integrity errors when trying to save to the db.

Excluding the field from model_fields and explicitly declaring it as:

project_description: str = ""

is a workaround.

From what I understand, Django encourages the use of blank without null for text fields to avoid a mix of empty values.

Versions (please complete the following information):

  • Python version: 3.11
  • Django version: 4.2
  • Django-Ninja version: 1.0b2
  • Pydantic version: 2.4
@michalwerner
Copy link

I also stumbled upon this issue.
The fix seems to be simple but I'm not sure if it won't result in other issues or if and if so why this was intentional.
See draft PR: #1374

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