Peewee:减少一定长度后条件中断的地方

Peewee: reducing where conditionals break after a certain length

这是我的:

SomeTable.select.where(reduce(operator.or_, (SomeTable.stuff == entry for entry in big_list)))

当我在 big_list 中有一个相对较大的元素列表并且我得到这个时,问题就出现了:

RuntimeError: maximum recursion depth exceeded

是否有另一种方法可以解决这个问题而不涉及将列表分成几个块?

尝试了使用 any 的建议,这是我的错误:

Traceback (most recent call last):
  File "C:/Users/f9xk3li/Documents/GitHub/leoshop_web/leoshop_web/data_models/data_model.py", line 347, in <module>
    search_bins_all("BoA 0")
  File "C:/Users/f9xk3li/Documents/GitHub/leoshop_web/leoshop_web/data_models/data_model.py", line 179, in search_bins_all
    for d in generator.order_by(SomeTable.RetrievedDate.desc()):
  File "C:\Users\f9xk3li\AppData\Local\Continuum\Anaconda\lib\site-packages\peewee.py", line 282, in inner
    clone = self.clone()  # Assumes object implements `clone`.
  File "C:\Users\f9xk3li\AppData\Local\Continuum\Anaconda\lib\site-packages\peewee.py", line 2202, in clone
    return self._clone_attributes(query)
  File "C:\Users\f9xk3li\AppData\Local\Continuum\Anaconda\lib\site-packages\peewee.py", line 2412, in _clone_attributes
    query = super(SelectQuery, self)._clone_attributes(query)
  File "C:\Users\f9xk3li\AppData\Local\Continuum\Anaconda\lib\site-packages\peewee.py", line 2206, in _clone_attributes
    query._where = self._where.clone()
AttributeError: 'bool' object has no attribute 'clone'

这是代码

generator = SomeTable.select()
generator = generator.where(any(SomeTable.BIN == entry for entry in big_list))
for d in generator:
    ....

尝试...where(SomeTable.BIN.in_(big_list))

PeeWee 对于可以在其 where 子句中使用哪些内容以使用该库有限制。

http://docs.peewee-orm.com/en/latest/peewee/querying.html#query-operators

为了扩展 Jacob 对已批准答案的评论,我认为他是说您可以使用子查询而不是解析所有 ID。

例如

admin_users = User.select().where(User.is_admin == True)
admin_messages = Message.select().where(Message.user.in_(admin_users))