Opened 11 hours ago

Last modified 10 hours ago

#36813 assigned Cleanup/optimization

Convert system checks for max_length and max_digits to __init__() checks.

Reported by: Jacob Walls Owned by: Mehraz Hossain Rumman
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Simon Charette, Mehraz Hossain Rumman Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#28120 extended a system check validating CharField.max_length to also validate that booleans are not provided.

However, system checks only check model fields, not fields constructed for use in the output_field argument of an Expression, e.g. when using Cast(). (Invalid inputs to Cast() error out at the db level instead of raising nicely.)

I'm not suggesting to move a bunch of checks over to *Field.__init__(), but I am suggesting that for simple checks on isinstance and > 0 that we could error out in {Char,Decimal}Field.__init__ instead of via a system check, to catch additional usage mistakes.

Another use case besides output_field would be for database setup before tests run checks, as in #34727.

Change History (1)

comment:1 by Mehraz Hossain Rumman, 10 hours ago

Cc: Mehraz Hossain Rumman added
Owner: set to Mehraz Hossain Rumman
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top