Peewee:减少条件在一定长度后破裂的地方

时间:2015-06-22 14:29:22

标签: python peewee

这就是我所拥有的:

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

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

RuntimeError: maximum recursion depth exceeded

有没有其他方法可以解决这个问题,而不是将列表拆分成几个块?

尝试使用任何建议,这是我的错误:

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:
    ....

2 个答案:

答案 0 :(得分:1)

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

PeeWee对于where子句中可以使用的内容有限制,以便使用该库。

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

答案 1 :(得分:1)

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

E.G。

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