Strange issue with generic tag manager

88 views
Skip to first unread message

arct...@gmail.com

unread,
May 21, 2014, 3:29:03 PM5/21/14
to django...@googlegroups.com

I have had taggit working flawlessly until I recently made lots of changes to my codebase including an upgrade to Django 1.6.2 and at one point was playing with custom tag through models which I abandoned and went back to GenericTaggedItemBase .  I believe when playing with the through models I altered my database and can’t seem to get it back despite having run syncdb and migrate . 

 

A Pin model is set up with taggit like this:

tag = TaggableManager() // which should use the GenericTaggedItemBase

 

This djagno query gets the eror: qs = Tag.objects.filter(pin__in=qs).distinct().order_by('name')

                This query has been in place and working for quite some time, now all of a sudden it’s not working and I have no idea when It broke.  All other types of queries on pins with tags are working fine. such as pin.tags.all(), qs.filter(tags__name__exact="sometag"), etc...

 

Generates the following SQL with errors:

SELECT ••• FROM "taggit_tag" 

INNER JOIN "taggit_taggeditem" 

ON ( "taggit_tag"."id" = "taggit_taggeditem"."tag_id" )

 INNER JOIN "pins_pin" 

ON ( "taggit_taggeditem"."object_id" = "pins_pin"."id" 

AND("taggit_taggeditem"."content_type_id" = 18)) 

WHERE "pins_pin"."object_id" 

IN(SELECT ••• FROM "pins_pin" U0 INNER JOIN "taggit_taggeditem" U1 ON ( U0."id" = U1."object_id" AND(U1."content_type_id" = 18))

INNER JOIN "taggit_tag" U2 ON ( U1."tag_id" = U2."id" ) WHERE U2."name" = 'Architecture' )

 

The error is:

                pins_pin does not have an object_id, and nor should it since it should be using taggit_taggeditem to lookup the object_id.

                See above (WHERE "pins_pin"."object_id" )

 

My data base tables are set up as follows:

taggit_taggeditem:

-          id serial NOT NULL,

-          tag_id integer NOT NULL,

-          object_id integer NOT NULL,

-          content_type_id integer NOT NULL,

pins_pin:

-          id serial NOT NULL,

-          some other stuff, but NOT object_id….

 

The error message:

  "column pins_pin.object_id does not exist\nLINE 1: ...taggit_taggeditem\".\"content_type_id\" = 18)) WHERE \"pins_pin\"...\n      

rx...@counsyl.com

unread,
Sep 28, 2014, 10:48:03 PM9/28/14
to django...@googlegroups.com, arct...@gmail.com
I was running into the exact same problem trying to upgrade my codebase to Django 1.6, and I have a fix available in https://github.com/alex/django-taggit/pull/266. Although I encountered the issue due to the TaggableManager being added to a multi-table inheritance subclass, I think the fix should apply to all cases where the primary key is not "id".
Reply all
Reply to author
Forward
0 new messages