📝 TagSchema and RoleSchema do not enforce max_length, causing unhandled DB errors (#944)
What's wrong?
The Tag and Role Django models define name = CharField(max_length=100), but the corresponding Pydantic schemas accept any-length strings.
class TagSchema(pydantic.BaseModel):
name: str <!-----------------------------HERE
class RoleSchema(pydantic.BaseModel):
name: str <!-----------------------------HERE
When a client sends a name longer than 100 characters, Pydantic validation passes (HTTP 422 is never raised), and the value reaches the database layer where PostgreSQL raises DataError: value too long for type character varying(100). This results in an unhandled 500 instead of a proper 422 validation error. On SQLite the value is silently stored without truncation, masking the bug in tests.
How it should be?
Add max_length constraints to match the model definition:
class TagSchema(pydantic.BaseModel):
name: str = Field(max_length=100)
class RoleSchema(pydantic.BaseModel):
name: str = Field(max_length=100)
Used versions
0.7.0
OS information
MacOS
#bug #good_first_issue #help_wanted #django_modern_rest
sent via relator