﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3055	GenericRelation should squawk if pointed to a model that doesn't have a GenericForeignKey on it	panta@…	Marcos Moyano	"Originally discussed on [http://groups.google.it/group/django-users/browse_thread/thread/67ee07c8534abef2/02f9695cf07382b9 this django-users thread].

I'm restating here the problem for future reference and for more comfort.

The problem happens when using the following structure:

{{{
#!python
class Tag(models.Model):
   ...

class TaggedObject(models.Model):
   content_type = ...
   object_id = models.PositiveIntegerField(""Object ID"")
   tag = models.ForeignKey(Tag)

   content_object = models.GenericForeignKey()

class UserTaggedObject(models.Model):
   user = ...
   object_tag = models.ForeignKey(TaggedObject)

class ArticleAttachment(models.Model):
   ...
   tags = models.GenericRelation(TaggedObject)
   user_tags = models.GenericRelation(UserTaggedObject)
}}}

When deleting an !ArticleAttachment (with ''delete()''), I get an !OperationalError exception ''(1054, ""Unknown column 'object_id' in 'where clause'"")''. Drilling down through the backtrace, the offending SQL code is in:

{{{
django_src/django/db/backends/util.py in execute

  12. return self.cursor.execute(sql, params) ...

Local vars
Variable        Value

params          (5L,)
self            <django.db.backends.util.CursorDebugWrapper object at 0xb6cdda0c>
sql             'DELETE FROM `tags_usertaggedobject` WHERE `object_id` IN (%s)'
}}}

which seems wrong to me, because ''object_id'' is in ''tags_taggedobject''
and not ''tags_usertaggedobject''.

Marco
"	defect	closed	Database layer (models, ORM)	dev	major	fixed			Accepted	1	0	0	1	0	0
