GenericIPAddressField must not allow blank for NOT NULL fields
|Reported by:||Erik Romijn||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.
- 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 Changed 3 years ago by
|Patch needs improvement:||unset|