Opened 7 years ago

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

Download all attachments as: .zip

Change History (11)

comment:1 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 7 years ago by stugots

  • Owner changed from nobody to stugots

comment:3 Changed 7 years ago by stugots

  • Status changed from new to assigned

comment:4 Changed 7 years ago by stugots

  • Owner changed from stugots to nobody
  • Status changed from assigned to new

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

  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

comment:6 Changed 7 years ago by curtis

  • Owner changed from anonymous to curtis
  • Status changed from assigned to new

comment:7 Changed 7 years ago by curtis

  • Status changed from new to assigned

Changed 7 years ago by curtis

Change PhoneNumber from Int to Char field

comment:8 Changed 7 years ago by curtis

  • Has patch set

comment:9 Changed 6 years ago by thejaswi_puthraya

  • Component changed from Uncategorized to Database layer (models, ORM)

comment:10 Changed 6 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from assigned to closed

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