Opened 8 years ago

Closed 8 years ago

Last modified 5 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: master
Severity: Keywords:
Cc: kenneth.arnold@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

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 8 years ago.
Test
dj-foreignkey-typecheck-fix.patch (648 bytes) - added by Kenneth Arnold 8 years ago.
Fix

Download all attachments as: .zip

Change History (9)

Changed 8 years ago by Kenneth Arnold

Test

Changed 8 years ago by Kenneth Arnold

Fix

comment:1 Changed 8 years ago by Kenneth Arnold

Patch needs improvement: set

comment:2 Changed 8 years ago by Kenneth Arnold

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

comment:3 Changed 8 years ago by Kenneth Arnold

Cc: kenneth.arnold@… added

comment:4 Changed 8 years ago by Eric Holscher

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:5 Changed 8 years ago by Malcolm Tredinnick

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

comment:6 Changed 8 years ago by Malcolm Tredinnick

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 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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