Djongo 查询 BooleanField 失败
Djongo fails to query BooleanField
我的 Django 应用程序带有这样的模块:
class myApp(models.Model):
is_new = models.BooleanField(default=True)
more_fields = models.TextField(blank=True)
并使用 Djongo 作为数据库(mongodb)
我可以毫无问题地查询模块中的所有字段,但是,在筛选布尔字段时,如下所示:
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
这似乎是一个 Djongo 问题,除非以不同方式查询布尔字段
正在使用的版本:
- Django 3.2.5
- djongo 1.3.6
这似乎是 Djongo 的一个老问题(这里是最近 issue 大约一个月前针对同一个错误打开的)并且人们被迫使用 in
的解决方法查找:
myList = myApp.objects.filter(is_new__in=[False])
我的 Django 应用程序带有这样的模块:
class myApp(models.Model):
is_new = models.BooleanField(default=True)
more_fields = models.TextField(blank=True)
并使用 Djongo 作为数据库(mongodb)
我可以毫无问题地查询模块中的所有字段,但是,在筛选布尔字段时,如下所示:
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
这似乎是一个 Djongo 问题,除非以不同方式查询布尔字段
正在使用的版本:
- Django 3.2.5
- djongo 1.3.6
这似乎是 Djongo 的一个老问题(这里是最近 issue 大约一个月前针对同一个错误打开的)并且人们被迫使用 in
的解决方法查找:
myList = myApp.objects.filter(is_new__in=[False])