Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#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 Sasha Romijn, 12 years ago

Has patch: set

comment:2 by Marc Tamlyn, 12 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In ded95ccdce0ba983c405ddde9eb071e454245a94:

Fixed #20484 -- Added model validation for GenericIPAddressField

GenericIPAddressField must not allow blank for NOT NULL fields

Thanks Erik Romijn.

comment:4 by chrismedrela, 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.

comment:5 by Christopher Medrela <chris.medrela@…>, 11 years ago

In fb26c4996a0c4d41aa80d28ce65ab050ffe6df6b:

Fixed #20484 again -- added note to field documentation

comment:6 by Preston Holmes <preston@…>, 11 years ago

In cf041b883c6a089f0b113846918fdb074e465713:

Merge pull request #1453 from chrismedrela/ticket20484-improvement

Fixed #20484 again -- added note to field documentation

comment:7 by Tim Graham <timograham@…>, 11 years ago

In 6264e39c346a1b563dc0cbc31c5fb75830e032cb:

[1.6.x] Added note to GenericIPAddressField documentation

refs #20484

Backport of fb26c4996a from master

Note: See TracTickets for help on using tickets.
Back to Top