On Dec 11, 2011, at 11:55 AM, lestat wrote: > /sqlalchemy/sql/expression.py:1869: SAWarning: The IN-predicate on > "comment.reply_id" was invoked with an empty sequence. This results in > a contradiction, which nonetheless can be expensive to evaluate. > Consider alternative strategies for improved performance. > return self._in_impl(operators.in_op, operators.notin_op, other) > > I try fix this warning. > > user_comments_ids = tuple(x[0] for x in > getCommentsForUser(user_id).values('id')) > if user_comments_ids: > comments_replies = > Comment.query.filter(Comment.reply_id.in_(user_comments_ids)) > else: > # empty query > comments_replies = Comment.query.filter_by(id=None) > return comments_replies > > but exists better solution? > > Why not add to sqlalchemy Query method like .all(), .one(), new > method .none() like in django orm?
>From what I'm reading, none() just means "return an empty list". SQLA's >Query object is not generative beyond the point of all()/one(), it appears >like Django's .none() produces a generative construct. So the SQLAlchemy >analogue of .none() compared to .all() or one() would be "[]". As far as >a Django-like analogue, where the Query object would produce a >False-evaluating object which is then further usable in larger queries, >SQLAlchemy would prefer you simply don't add "False" predicates to your query >- it's a situation that can't be concealed without leading to inefficient or >unnecessary queries. In the above case, you'd just say "comments_replies = []". My understanding is that Django resolves "x.in_([])" to an expression like "false", or "1 != 1". This approach isn't correct in all cases, namely "NOT (x IN ())" where "x" is NULL. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.