Skip to content

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

Open
@jam13

Description

@jam13

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions