dlamotte / django-tagging

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

django ignoring MySQL results for "in" operator #180

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I realise that this is not caused directly by the tagging app, but I'm
posting here because the problem is manifesting itself within the tagging
app, and I've had no luck on other forums.

I'm using django 1.0.2 and the tagging app to retrieve a tag via a
database "in" query, and something is causing the "in" operator's
native nehaviour to be ignored.

In particular, this line of code from tagging.utils.get_tag_list()
executes:

return Tag.objects.filter(name__in=[force_unicode(tag)
                          for tag in tags])

and at this point:
(Pdb) p tags
[u'sea']

The thread of execution can be traced into the method
django.db.models.sql.query.execute_sql(self, result_type=MULTI), and
to this line of code:

        cursor.execute(sql, params)

and over here:
>
c:\python26\lib\site-packages\django\db\models\sql\query.py(1735)execute_sql()

-> cursor.execute(sql, params)
(Pdb) p sql
'SELECT "tagging_tag"."id", "tagging_tag"."name" FROM "tagging_tag"
WHERE "tagging_tag"."name" IN (%s) ORDER BY "tagging_tag"."name" ASC'
(Pdb) p params
(u'sea',)
(Pdb)

If I audit what's submitted to MySQL via MySQL logging, it reports:
SELECT `tagging_tag`.`id`, `tagging_tag`.`name` FROM `tagging_tag`
WHERE `tagging_tag`.`name` IN ('sea') ORDER BY `tagging_tag`.`name`
ASC

which looks correct - however django returns an empty list.

If I execute the query interactively in MySQL, I get the expected
result:

+----+------+
| id | name |
+----+------+
| 28 | Sea  |
+----+------+
1 row in set (0.00 sec)

I suspect this is a configuration problem but have no idea where to
look - can anyone help?

Thanks 

Original issue reported on code.google.com by jad...@gmail.com on 5 Jan 2009 at 8:30