Opened 16 years ago

Closed 15 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: dev
Severity: 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

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 16 years ago.
Change PhoneNumber from Int to Char field

Download all attachments as: .zip

Change History (11)

comment:1 by Malcolm Tredinnick, 16 years ago

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 by John DeRosa, 16 years ago

Owner: changed from nobody to John DeRosa

comment:3 by John DeRosa, 16 years ago

Status: newassigned

comment:4 by John DeRosa, 16 years ago

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 by Curtis Thompson <curtis.thompson@…>, 16 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:6 by curtis, 16 years ago

Owner: changed from anonymous to curtis
Status: assignednew

comment:7 by curtis, 16 years ago

Status: newassigned

by curtis, 16 years ago

Attachment: 6637.diff added

Change PhoneNumber from Int to Char field

comment:8 by curtis, 16 years ago

Has patch: set

comment:9 by Thejaswi Puthraya, 15 years ago

Component: UncategorizedDatabase layer (models, ORM)

comment:10 by Chris Beaven, 15 years ago

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