#20484 closed Bug (fixed)
GenericIPAddressField must not allow blank for NOT NULL fields
Reported by: | Sasha Romijn | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | eromijn@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
GenericIPAddressField internally translates all blank values, e.g. an empty string, to None/NULL before saving them in the database. This is good, because in PostgreSQL this field is backed by INET, meaning an empty string is not allowed (this problem also affects IPAddressField, but we can't change it as it would break backwards compatibility, #5622).
However, this means that a field which allows blank but not null values, will trigger a database error at runtime when trying to save a blank value. Therefore, the model validation should not allow GenericIPAddressFields to have blank but not null.
To summarise:
- Current behaviour: when storing a blank value in a
GenericIPAddressField(blank=True, null=False)
, a database exception will be triggered - New behaviour: a
GenericIPAddressField(blank=True, null=False)
will trigger a model validation error
Change History (7)
comment:1 by , 12 years ago
Has patch: | set |
---|
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 11 years ago
This patch includes no doc in docs/ref/models/fields.txt
. I've created a pull request with a note in the file: https://github.com/django/django/pull/1453.
Pull request in: https://github.com/django/django/pull/1204