views:

174

answers:

1

I am building Django +MySQL on dreamhost, but met the error messages:
Caught an exception while rendering: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY tag.used_count DESC, tag.name ASC' at line 1")

I traced hard and found the error splot is with the function below:
Can you someone help me check what's wrong with this code?

 def get_tags_by_questions(self, questions):
    question_ids = []
    for question in questions:
        question_ids.append(question.id)

    question_ids_str = ','.join([force_unicode(id) for id in question_ids])
    related_tags = self.extra(
            tables=['tag', 'question_tags'],
            where=["tag.id = question_tags.tag_id AND question_tags.question_id IN (" + question_ids_str + ")"]
    ).distinct()

    return related_tags
+2  A: 

Is it possible that there are no questions, in which case the SQL will contain something like "WHERE question_id IN ()" which wouldn't be valid SQL.

samjudson