[Python] Djongo fails to query BooleanField

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have Django application with a module like this:

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



    And using Djongo for database (which is mongodb)

    I can query all fields in the module with no issues, however, when filtering for a boolean field like the following:

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

    for record in myList: ....


    It fails with the following error:

    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


    It seems like a Djongo issue unless boolean fields are queried differently

    Versions in use:

    • Django 3.2.5
    • djongo 1.3.6

    Continue reading...

Compartilhe esta Página