Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26557 closed Bug (fixed)

GenericIPAddressField no longer normalises empty values to None

Reported by: Joshua Phillips Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The GenericIPAddressField is documented to convert empty strings to None when saving models and when filtering and updating: "If you allow for blank values, you have to allow for null values since blank values are stored as null."

#24092 broke this:

-        return value or None
+        return connection.ops.value_to_db_ipaddress(value)
+    def value_to_db_ipaddress(self, value):
+        """
+        Transforms a string representation of an IP address into the expected
+        type for the backend driver.
+        """
+        return value

The default value_to_db_ipaddress function doesn't convert empty strings to None, like the code it replaced did. This is particularly important when using a ModelForm, since forms.GenericIPAddressField sets the model's field to an empty string if the field is not provided.

Change History (7)

comment:1 by Tim Graham, 8 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 by Joshua Phillips, 8 years ago

Has patch: set
Last edited 8 years ago by Tim Graham (previous) (diff)

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

Resolution: fixed
Status: newclosed

In 4681d650:

Fixed #26557 -- Converted empty strings to None when saving GenericIPAddressField.

comment:4 by Tim Graham <timograham@…>, 8 years ago

In e0af590b:

[1.9.x] Fixed #26557 -- Converted empty strings to None when saving GenericIPAddressField.

Backport of 4681d65048ca2553895e10c2c492997b0a78ffba from master

comment:5 by Tim Graham <timograham@…>, 8 years ago

In 052e1f1:

[1.8.x] Fixed #26557 -- Converted empty strings to None when saving GenericIPAddressField.

Backport of 4681d65048ca2553895e10c2c492997b0a78ffba from master

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 9f8941e:

Refs #26557 -- Added forgotten release notes.

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

In 999e023:

[1.9.x] Refs #26557 -- Added forgotten release notes.

Backport of 9f8941eda4b98044d0bf0fea6bb3ba579d382109 from master

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