#7498 closed (fixed)
ForeignKey doesn't check type on __init__
| Reported by: | Kenneth Arnold | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | kenneth.arnold@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
The ForeignKey descriptor gives a ValueError (hm, should be a TypeError?) on assigning an invalidly typed object to a foreign key. But for __init__, it accepts anything that has a id field without question.
Testcase and initial patch attached. I'm marking "needs better patch" because I think the AttributeError case is no longer necessary, but I'm not sure. Also, the TypeError that is raised (in the existing code) could be more helpful.
This breaks a few things in regressiontests/queries/models.py, but I think those are test bugs (the variable n1 is used both as a Note and a Number).
Attachments (2)
Change History (9)
by , 17 years ago
| Attachment: | dj-foreignkey-typecheck-testcase.patch added |
|---|
comment:1 by , 17 years ago
| Patch needs improvement: | set |
|---|
comment:2 by , 17 years ago
| Summary: | ForeignKey doesn't check type on {{{__init__}}} → ForeignKey doesn't check type on __init__ |
|---|
comment:3 by , 17 years ago
| Cc: | added |
|---|
comment:4 by , 17 years ago
| milestone: | → 1.0 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:5 by , 17 years ago
comment:6 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
This was fixed as a side-effect of [8185], but I committed your test to make sure it stays that way. Thanks,
Test