[Django] #35445: Adding model field validators to FloatField and IntegerField is not possible.

10 views
Skip to first unread message

Django

unread,
May 11, 2024, 10:04:47 AM5/11/24
to django-...@googlegroups.com
#35445: Adding model field validators to FloatField and IntegerField is not
possible.
-------------------------------------+-------------------------------------
Reporter: | Owner: AjmalPonneth
AjmalPonneth |
Type: Bug | Status: assigned
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Adding validators like MinLengthValidator, and MaxLengthValidator to the
float field causes a TypeError "object of type 'float' has no len()" when
saving the instance from admin.
--
Ticket URL: <https://code.djangoproject.com/ticket/35445>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 13, 2024, 2:31:30 AM5/13/24
to django-...@googlegroups.com
#35445: Adding model field validators to FloatField and IntegerField is not
possible.
------------------------------+----------------------------------------
Reporter: AjmalPonneth | Owner: AjmalPonneth
Type: Bug | Status: closed
Component: Core (Other) | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Sarah Boyce):

* component: Database layer (models, ORM) => Core (Other)
* resolution: => invalid
* status: assigned => closed

Comment:

Hi AjmalPonneth,
MinLengthValidator and MaxLengthValidator are not meant to be used for
floats as it is checking the length. You may want to use MinValueValidator
and MaxValueValidator.
If you want to make some tweaks to the docs around which types the
validators can be used for, feel free 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35445#comment:1>
Reply all
Reply to author
Forward
0 new messages