Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7498 closed (fixed)

ForeignKey doesn't check type on __init__

Reported by: kcarnold 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 kcarnold 6 years ago.
Test
dj-foreignkey-typecheck-fix.patch (648 bytes) - added by kcarnold 6 years ago.
Fix

Download all attachments as: .zip

Change History (9)

Changed 6 years ago by kcarnold

Test

Changed 6 years ago by kcarnold

Fix

comment:1 Changed 6 years ago by kcarnold

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set

comment:2 Changed 6 years ago by kcarnold

  • Summary changed from ForeignKey doesn't check type on {{{__init__}}} to ForeignKey doesn't check type on __init__

comment:3 Changed 6 years ago by kcarnold

  • Cc kenneth.arnold@… added

comment:4 Changed 6 years ago by ericholscher

  • milestone set to 1.0
  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 6 years ago by mtredinnick

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

comment:6 Changed 6 years ago by mtredinnick

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

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 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.