rohitjain-rj / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
0 stars 0 forks source link

calculate_cloud fails sometimes on mysql #202

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This view code fails on mysql (OperationalError), but seems ok with sqlite.
It fails only when I give it a tag name through GET.

def index(request):
    data = get_standard_sidebar_contents()

    # if tag is given, filter the article list by tag
    tag = request.GET.get('tag')
    if tag:
        article_list = TaggedItem.objects.get_by_model(Article,
tag).filter(is_news_item=True, published=True)
    else:
        article_list = Article.objects.filter(is_news_item=True,
published=True)
    data['article_list'] = article_list
    data['tag_list'] =
calculate_cloud(Tag.objects.usage_for_queryset(article_list, counts=True))
    return render_to_response('index.html', data,
context_instance=RequestContext(request))

Here's the important parts of the traceback

 File "djcode/apps/views.py", line 19, in index
   data['tag_list'] =
calculate_cloud(Tag.objects.usage_for_queryset(article_list, counts=True))

 File "djcode/external_apps/tagging/models.py", line 172, in usage_for_queryset
   return self._get_usage(queryset.model, counts, min_count, extra_joins,
extra_criteria, params)

 File "djcode/external_apps/tagging/models.py", line 116, in _get_usage
   cursor.execute(query % (extra_joins, extra_criteria, min_count_sql), params)

And this is the query which fails

        SELECT DISTINCT `tagging_tag`.id, `tagging_tag`.name,
COUNT(`blog_article`.`id`)
        FROM                                                              

            `tagging_tag`                                                 

            INNER JOIN `tagging_taggeditem`                               

                ON `tagging_tag`.id = `tagging_taggeditem`.tag_id         

            INNER JOIN `blog_article`                                     

                ON `tagging_taggeditem`.object_id = `blog_article`.`id`
            , `tagging_taggeditem`
        WHERE `tagging_taggeditem`.content_type_id = 12
            AND (`blog_article`.`is_news_item` = %s  AND
`blog_article`.`published` = %s )
        GROUP BY `tagging_tag`.id, `tagging_tag`.name

        ORDER BY `tagging_tag`.name ASC

(params=[True, True])

The problem is with the second part of the ON clause (I don't know what it
means), but it seems ok if I remove it.

Original issue reported on code.google.com by deuns.ma...@gmail.com on 4 Jul 2009 at 12:56

GoogleCodeExporter commented 9 years ago
I fixed this on my project. It happens on all querysets where FROM contains
tagging_taggeditem.
I made a patch, it's here:

http://mupuf.org/media/files/tagging-sql.patch

Original comment by deuns.ma...@gmail.com on 18 Jul 2009 at 10:14