Django

Code

Ticket #7026 (closed: fixed)

Opened 6 months ago

Last modified 4 months ago

Exception message is worded poorly (backwards)

Reported by: ryan@peaceworks.ca Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: models many-to-many manytomany m2m exception primary key pk
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

This occurs with recent SVN checkout. (trimmed) example models:

class Tag(models.Model):
    name = models.CharField(max_length=127, unique=True)
class Image(models.Model):
    tags = models.ManyToManyField(Tag)

code which bombs:

t = Tag(name='foo')
t.save()
i = Image()
i.tags.add(t) #Bombs here because i doesn't have a pk
Traceback
  File "reloadDB.py", line 73, in ?
    i.tags.add(t)
  File "/usr/lib/python2.4/site-packages/django/db/models/fields/related.py", line 485, in __get__
    target_col_name=qn(self.field.m2m_reverse_name())
  File "/usr/lib/python2.4/site-packages/django/db/models/fields/related.py", line 317, in __init__
    raise ValueError("%r instance needs to have a primary key value before a many-to-many relationship can be used." % model)
ValueError: <class 'eTrain.models.Tag'> instance needs to have a primary key value before a many-to-many relationship can be used.

The error should indicate the <class 'eTrain.models.Image'> instance doesn't have pk... I'm not sure how to get at this as superclass doesn't seem to have the model attribute set.

Attachments

Change History

06/10/08 21:51:49 changed by programmerq

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • component changed from Uncategorized to Database wrapper.
  • needs_tests changed.
  • needs_docs changed.

I also ran into this error: I was stumped because I knew that what it was saying was wrong.

06/11/08 23:13:16 changed by adrian

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

(In [7622]) Fixed #7026 -- Fixed misleading/incorrect exception text when adding to a many-to-many set on an object that doesn't yet have a primary-key value. Thanks for the report, ryan@peaceworks.ca


Add/Change #7026 (Exception message is worded poorly (backwards))




Change Properties
Action