[Sqlalchemy-tickets] Issue #2995: Query.exists() fails if the query doesn't select any columns (wor
Brought to you by:
zzzeek
|
From: Daniel G. <iss...@bi...> - 2014-03-17 18:06:09
|
New issue 2995: Query.exists() fails if the query doesn't select any columns (worked in 0.8.x) https://bitbucket.org/zzzeek/sqlalchemy/issue/2995/queryexists-fails-if-the-query-doesnt Daniel Grace: This appears to be a regression: This (pseudocode) used to run with no issues in 0.8.x: [...] subquery = session.query().select_from(Bar) # Note no selected columns query = query.filter(subquery.exists()) Now it fails on the .exists() line with the following exception: sqlalchemy.exc.InvalidRequestError: Query contains no columns with which to SELECT from The documentation for .exists() states that it is a "A convenience method that turns a query into an EXISTS subquery of the form EXISTS (SELECT 1 FROM ... WHERE ...).". Thus, there should be no need for the subquery to select any columns of its own since they will all be replaced by the implicit "SELECT 1" from the exists anyways. Rewriting the above as: subquery = session.query().select_from(Bar) query = query.filter(subquery.add_columns(sql.true()).exists()) avoids the exception and makes the query work as intended. |