Django

Code

Ticket #7498 (closed: fixed)

Opened 6 months ago

Last modified 3 months ago

ForeignKey doesn't check type on __init__

Reported by: kcarnold Assigned to: nobody
Milestone: 1.0 Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: kenneth.arnold@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

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

dj-foreignkey-typecheck-testcase.patch (0.7 kB) - added by kcarnold on 06/18/08 14:18:27.
Test
dj-foreignkey-typecheck-fix.patch (0.6 kB) - added by kcarnold on 06/18/08 14:21:30.
Fix

Change History

06/18/08 14:18:27 changed by kcarnold

  • attachment dj-foreignkey-typecheck-testcase.patch added.

Test

06/18/08 14:21:30 changed by kcarnold

  • attachment dj-foreignkey-typecheck-fix.patch added.

Fix

06/18/08 14:21:53 changed by kcarnold

  • needs_better_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

06/18/08 14:22:04 changed by kcarnold

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

08/04/08 15:14:38 changed by kcarnold

  • cc set to kenneth.arnold@gmail.com.

08/08/08 14:21:54 changed by ericholscher

  • stage changed from Unreviewed to Accepted.
  • milestone set to 1.0.

08/27/08 00:44:27 changed by mtredinnick

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

08/27/08 00:45:12 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #7498 (ForeignKey doesn't check type on __init__)




Change Properties
Action