在 SQL 中,我可以得到一组这样的行:
SELECT * FROM table WHERE id in (2,3,5,7,11);
等效的 sqlalchemy 查询看起来如何?cls.id in [2,3,5,7,11]
计算结果为False
,所以这段代码:
q = meta.Session.query(cls)
q = q.filter(cls.id in [2,3,5,7,11])
return q.all()
失败但有异常:
File "foo.py", line 1234, in findall_by_ids
q = q.filter(cls.id in [2,3,5,7,11])
File "<string>", line 1, in <lambda>
File "/eggs/sqlalchemy/orm/query.py", line 50, in generate
fn(self, *args[1:], **kw)
File "/eggs/sqlalchemy/orm/query.py", line 1177, in filter
"filter() argument must be of type "
ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement
or string