Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#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)

dj-foreignkey-typecheck-testcase.patch (673 bytes ) - added by Kenneth Arnold 16 years ago.
Test
dj-foreignkey-typecheck-fix.patch (648 bytes ) - added by Kenneth Arnold 16 years ago.
Fix

Download all attachments as: .zip

Change History (9)

by Kenneth Arnold, 16 years ago

Test

by Kenneth Arnold, 16 years ago

Fix

comment:1 by Kenneth Arnold, 16 years ago

Patch needs improvement: set

comment:2 by Kenneth Arnold, 16 years ago

Summary: ForeignKey doesn't check type on {{{__init__}}}ForeignKey doesn't check type on __init__

comment:3 by Kenneth Arnold, 16 years ago

Cc: kenneth.arnold@… added

comment:4 by Eric Holscher, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:5 by Malcolm Tredinnick, 16 years ago

(In [8609]) Added a test from kcarnold to show that #7498 is fixed. Refs #7498.

comment:6 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

This was fixed as a side-effect of [8185], but I committed your test to make sure it stays that way. Thanks,

comment:7 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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