Opened 9 years ago

Closed 7 years ago

#6637 closed (fixed)

PhoneNumberField set to null=False and blank=True doesn't allow empty string

Reported by: anonymous Owned by: curtis
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I had model that used PhoneNumberField and it was optional, so set it to blank=True. I was dumping data and loading data using load data. When I did it complained because the field had "", which it said that the field couldn't be null. The CharFields didn't have the same issue. The only way I could load the data was to set the field equal to null. This is a bug, because null and empty are different even if it's a phone number.

Attachments (1)

6637.diff (3.7 KB) - added by curtis 9 years ago.
Change PhoneNumber from Int to Char field

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by Malcolm Tredinnick

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

This is a mess. The root problem here is that PhoneNumberField inherits from IntegerField in django/db/models/fields/__init__.py, but everywhere else it is treated as text: in its validator and in the database column we create (varchar(20))! Integer fields cannot have empty values, so we convert them to NULLs, leading to the problem noticed by the reporter.

I suspect the solution is to change the parent of PhoneNumberField and make sure the validation checks for all digits. However there may be unintended side-effects and backwards-incompatibilities there, so it needs checking.

comment:2 Changed 9 years ago by John DeRosa

Owner: changed from nobody to John DeRosa

comment:3 Changed 9 years ago by John DeRosa

Status: newassigned

comment:4 Changed 9 years ago by John DeRosa

Owner: changed from John DeRosa to nobody
Status: assignednew

I've held on to this for too long. Other things keep getting in the way of working on this. So I'm releasing it back into the nobody ticket pool.

comment:5 Changed 9 years ago by Curtis Thompson <curtis.thompson@…>

Owner: changed from nobody to anonymous
Status: newassigned

comment:6 Changed 9 years ago by curtis

Owner: changed from anonymous to curtis
Status: assignednew

comment:7 Changed 9 years ago by curtis

Status: newassigned

Changed 9 years ago by curtis

Attachment: 6637.diff added

Change PhoneNumber from Int to Char field

comment:8 Changed 9 years ago by curtis

Has patch: set

comment:9 Changed 7 years ago by Thejaswi Puthraya

Component: UncategorizedDatabase layer (models, ORM)

comment:10 Changed 7 years ago by Chris Beaven

Resolution: fixed
Status: assignedclosed

Seems like this was fixed somewhere along the line -- PhoneNumberField in django.contrib.localflavor.us.models subclasses Field.

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