Opened 18 years ago
Closed 16 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)
Change History (11)
comment:1 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 18 years ago
| Owner: | changed from to |
|---|
comment:3 by , 18 years ago
| Status: | new → assigned |
|---|
comment:4 by , 18 years ago
| Owner: | changed from to |
|---|---|
| Status: | assigned → 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 by , 18 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:6 by , 18 years ago
| Owner: | changed from to |
|---|---|
| Status: | assigned → new |
comment:7 by , 18 years ago
| Status: | new → assigned |
|---|
comment:8 by , 18 years ago
| Has patch: | set |
|---|
comment:9 by , 17 years ago
| Component: | Uncategorized → Database layer (models, ORM) |
|---|
comment:10 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Seems like this was fixed somewhere along the line -- PhoneNumberField in django.contrib.localflavor.us.models subclasses Field.
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.