#20205: PositiveIntegerfield does not handle empty values well
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: Jacob
| Walls
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):
* status: assigned => closed
* resolution: => wontfix
Comment:
Per [https://groups.google.com/g/django-developers/c/GlYM25fdRnA mailing
list discussion] we cannot envision making behavior changes here because
we neither want to remove the blankable-and-not-nullable-and-inject-data-
on-save idiom nor silently cast data in ways a developer might not expect.
I collected some comments about the blank=True, null=False idiom on #22224
and will reframe it as a documentation task.
> That said, this is a way for someone to shoot themselves in the foot,
and the error message could be cleaner. One possible way forward would be
for Field.get_prep_value to check if the field has empty_strings_allowed =
False, and if so and if the value is an empty string, to throw some type
of error with a more meaningful error message. That said, it's not
strictly necessary, as someone will likely find this very thread from the
current error message, and realize what the problem is.
I think the current error (assuming it's in a similar form today to the
original `invalid literal for int(): ''`) points out that `''` is not an
int, so in my opinion, I wouldn't add a particularized exception for folks
using any single particular poor combination of form and model fields.
--
Ticket URL: <https://code.djangoproject.com/ticket/20205#comment:25>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.2f7e9893c4d2dcb0bca3f5f8ea93a6ac%40djangoproject.com.