query.filter(cond).filter_by() produces invalid SQL

Issue #1423 resolved
Former user created an issue

session.filter(some_cond).filter_by(**kwargs).first() produces broken SQL when kwargs is empty dictionary: ... WHERE <some_cond> AND ORDER BY ...

Here is error message from my real-life project:

ProgrammingError: (ProgrammingError) (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
`Doc`.date DESC \n LIMIT 0, 1' at line 3") u'SELECT `Doc`.id AS `Doc_id`, `Doc`.type AS
`Doc_type`, `Doc`.date AS `Doc_date`, `Doc`.state AS `Doc_state`, `Doc`.place AS `Doc_place`, 
`Doc`.title AS `Doc_title` \nFROM `Doc` \nWHERE `Doc`.state = %s AND  ORDER BY `Doc`.date DESC 
\n LIMIT 0, 1' [4](4)

Using SQLAlchemy 0.5.4p1. This is probably related to the ticket #1011.

Comments (1)

  1. Log in to comment