gpt4 book ai didi

python - Djongo 查询 BooleanField 失败

转载 作者:行者123 更新时间:2023-12-05 09:31:47 26 4
gpt4 key购买 nike

我的 Django 应用程序有这样一个模块:

class myApp(models.Model):
is_new = models.BooleanField(default=True)
more_fields = models.TextField(blank=True)

并使用 Djongo 作为数据库(即 mongodb)

我可以毫无问题地查询模块中的所有字段,但是,在过滤 bool 字段时,如下所示:

    myList = myApp.objects.filter(is_new=False)

for record in myList: ....

失败并出现以下错误:

  File "/home/user/myApp/venv/lib64/python3.9/site-packages/djongo/sql2mongo/operators.py", line 258, in evaluate
self.rhs.negate()
AttributeError: 'NoneType' object has no attribute 'negate'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/user/myApp/venv/lib64/python3.9/site-packages/djongo/cursor.py", line 51, in execute
self.result = Query(
File "/home/user/myApp/venv/lib64/python3.9/site-packages/djongo/sql2mongo/query.py", line 784, in __init__
self._query = self.parse()
File "/home/user/myApp/venv/lib64/python3.9/site-packages/djongo/sql2mongo/query.py", line 885, in parse
raise exe from e
djongo.exceptions.SQLDecodeError:

Keyword: None
Sub SQL: None
FAILED SQL: SELECT "mysite_myapp"."more_fields", "mysite_myapp"."is_new" FROM "mysite_myapp" WHERE NOT "mysite_myapp"."is_new"
Params: ()
Version: 1.3.6

除非以不同方式查询 bool 字段,否则这似乎是 Djongo 问题

正在使用的版本:

  • Django 3.2.5
  • 琼戈 1.3.6

最佳答案

这似乎是 Djongo 的一个老问题(这里是大约一个月前针对同一个错误打开的最近 issue)并且人们被迫使用 in 查找的解决方法:

myList = myApp.objects.filter(is_new__in=[False])

关于python - Djongo 查询 BooleanField 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68609027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com