#36842 closed New feature (wontfix)
HTML validation of non-float values in admin number widgets allows submitting invalid entries to succeed if blank=True
| Reported by: | pawel-steto | Owned by: | Vishy Algo |
|---|---|---|---|
| Component: | contrib.admin | Version: | 6.0 |
| Severity: | Normal | Keywords: | admin validation floatfield blank input number |
| Cc: | pawel-steto | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hello,
Having the following model and associated admin:
from django.db import models
class FooBar(models.Model):
float_req = models.FloatField()
float_not_req = models.FloatField(null=True, blank=True)
from django.contrib import admin from .models import FooBar admin.site.register(FooBar)
If you:
- Create an entry with both float fields set
- In django admin, edit the float_not_req field entering an invalid float (a string for example)
- Save the model
No issue is shown, the value of the field is overridden and set to None
But If you do the same for the required float field, a validation error is raised and the field is not overridden.
I know it is possible to change this behavior overriding the save/clean logic in django admin but I think this is misleading.
Have a nice day,
Pawel
Change History (3)
comment:1 by , 3 days ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , 3 days ago
| Resolution: | → wontfix |
|---|---|
| Status: | assigned → closed |
| Type: | Uncategorized → New feature |
comment:3 by , 3 days ago
| Keywords: | input number added |
|---|---|
| Summary: | Blank FloatField validation is not run on django admin and value is lost on edition. → HTML validation of non-float values in admin number widgets allows submitting invalid entries to succeed if blank=True |
Note:
See TracTickets
for help on using tickets.
Thanks for the ticket. Admin widgets have used
type="number"since #27199, with the result that nonsense values get cleaned by the browser to"", and thus never make it to Django.If this is not desired, a workaround is documented (however, and TIL --
novalidatehas no effect ontype="number", so your workarounds are reduced to just usingTextInput.):If your proposal is to revert #27199, it would present compatibility concerns and should be discussed first on the Forum (internals).