|
List Info
Thread: Strange behaviour when deleting object with generic relation
|
|
| Strange behaviour when deleting object
with generic relation |

|
2006-11-21 09:34:04 |
Hi,
I get a SQL error when deleting an object with a somewhat
complex
generic relation (the relation is to a model with a foreign
key to the
model with the GenericForeignKey).
The simplified structure is:
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)
then, when I delete an ArticleAttachment with delete(), I
get an
OperationalError exception, with (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:
mysql> describe tags_taggedobject;
+-----------------+------------------+------+-----+---------
+----------------+
| Field | Type | Null | Key | Default
| Extra |
+-----------------+------------------+------+-----+---------
+----------------+
| id | int(11) | | PRI | NULL
| auto_increment |
| content_type_id | int(11) | | MUL | 0
| |
| object_id | int(10) unsigned | | | 0
| |
| tag_id | int(11) | | MUL | 0
| |
+-----------------+------------------+------+-----+---------
+----------------+
mysql> describe tags_usertaggedobject;
+---------------+---------+------+-----+---------+----------
------+
| Field | Type | Null | Key | Default | Extra
|
+---------------+---------+------+-----+---------+----------
------+
| id | int(11) | | PRI | NULL |
auto_increment |
| user_id | int(11) | | MUL | 0 |
|
| object_tag_id | int(11) | | MUL | 0 |
|
+---------------+---------+------+-----+---------+----------
------+
Is this an error on my part? What am I doing wrong?
Thank you in advance.
Ciao,
Marco
--
Marco Pantaleoni
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Strange behaviour when deleting object
with generic relation |

|
2006-11-23 08:51:54 |
Hi,
doesn't someone have any idea about this?
I'd really appreciate any help or suggestion.
Thanks!
Cheers,
Marco
Marco Pantaleoni wrote:
> Hi,
> I get a SQL error when deleting an object with a
somewhat complex
> generic relation (the relation is to a model with a
foreign key to the
> model with the GenericForeignKey).
> The simplified structure is:
>
> 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)
>
> then, when I delete an ArticleAttachment with delete(),
I get an
> OperationalError exception, with (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:
>
> mysql> describe tags_taggedobject;
>
+-----------------+------------------+------+-----+---------
+----------------+
> | Field | Type | Null | Key |
Default | Extra |
>
+-----------------+------------------+------+-----+---------
+----------------+
> | id | int(11) | | PRI |
NULL | auto_increment |
> | content_type_id | int(11) | | MUL | 0
| |
> | object_id | int(10) unsigned | | | 0
| |
> | tag_id | int(11) | | MUL | 0
| |
>
+-----------------+------------------+------+-----+---------
+----------------+
>
> mysql> describe tags_usertaggedobject;
>
+---------------+---------+------+-----+---------+----------
------+
> | Field | Type | Null | Key | Default |
Extra |
>
+---------------+---------+------+-----+---------+----------
------+
> | id | int(11) | | PRI | NULL |
auto_increment |
> | user_id | int(11) | | MUL | 0 |
|
> | object_tag_id | int(11) | | MUL | 0 |
|
>
+---------------+---------+------+-----+---------+----------
------+
>
> Is this an error on my part? What am I doing wrong?
> Thank you in advance.
>
> Ciao,
> Marco
>
> --
> Marco Pantaleoni
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Strange behaviour when deleting object
with generic relation |

|
2006-11-23 09:31:28 |
Hi panta,
panta schrieb:
>> I get a SQL error when deleting an object with a
somewhat complex
>> generic relation (the relation is to a model with a
foreign key to the
>> model with the GenericForeignKey).
>> The simplified structure is:
>>
>> 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)
I assume that in ArticleAttachment, tags is somehow
different
from the tags you get via user_tags. (If it is the same,
then
it's probably better to remove tags and join via user_tags).
Yeah, Django's ORM does have some problems when the same
table
(the one for TaggedObject) is joined multiple times, be it
directly or indirectly. I don't have any experience with
GenericRelations, but I guess it's a bug in Django. Would
you
please file a ticket for this so that it doesn't get lost?
Sorry,
but I have no idea for a good work-around.
Michael
--
noris network AG - Deutschherrnstraße 15-19 - D-90429
Nürnberg -
Tel +49-911-9352-0 - Fax +49-911-9352-100
http://www.noris.de - The
IT-Outsourcing Company
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Strange behaviour when deleting object
with generic relation |

|
2006-11-23 09:48:31 |
Michael Radziej wrote:
> Hi panta,
>
> >>
> >> class ArticleAttachment(models.Model):
> >> ...
> >> tags = models.GenericRelation(TaggedObject)
> >> user_tags =
models.GenericRelation(UserTaggedObject)
>
> I assume that in ArticleAttachment, tags is somehow
different
> from the tags you get via user_tags. (If it is the
same, then
> it's probably better to remove tags and join via
user_tags).
yes, user_tags are tags "owned" by specific users,
while tags are set
by the editors and have no "owner".
>
> Yeah, Django's ORM does have some problems when the
same table
> (the one for TaggedObject) is joined multiple times, be
it
> directly or indirectly. I don't have any experience
with
> GenericRelations, but I guess it's a bug in Django.
Would you
> please file a ticket for this so that it doesn't get
lost? Sorry,
> but I have no idea for a good work-around.
>
> Michael
Ok, understood. I'll try to work-around this by replicating
TaggedObject fields in UserTaggedObject,
thus avoiding the indirection to the same table. This should
eliminate
the multiple (indirect) join.
I'll also file a ticket, following your suggestion.
Thank you for your help.
Ciao,
Marco
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-4]
|
|