Skip to content

BooleanField not working as expected with filter #62

@jrmi

Description

@jrmi

When I try to filter a model by a boolean property with an sqlite DB i get this error:

Traceback (most recent call last):
  File "buggy.py", line 31, in <module>
    loop.run_until_complete(init())
  File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
    return future.result()
  File "buggy.py", line 23, in init
    result = await Tournament.filter(bool_field=True)
  File "…/Code/tortoise-orm/tortoise/queryset.py", line 479, in _execute
    self.query, custom_fields=list(self._annotations.keys())
  File "…/Code/tortoise-orm/tortoise/backends/base/executor.py", line 24, in execute_select
    raw_results = await self.connection.execute_query(str(query))
  File "…/Code/tortoise-orm/tortoise/backends/sqlite/client.py", line 23, in wrapped
    raise OperationalError(exc)
tortoise.exceptions.OperationalError: no such column: true

You can reproduce this bug by executing this code:

import asyncio
from tortoise import Tortoise
from tortoise.models import Model
from tortoise import fields

class Tournament(Model):
    id = fields.IntField(pk=True)
    bool_field = fields.BooleanField()

    def __str__(self):
        return self.name

async def init():
    await Tortoise.init(
        db_url='sqlite://:memory:',
        modules={'models': ['__main__']}
    )
    await Tortoise.generate_schemas()
    result = await Tournament.filter(bool_field=True)
    await Tortoise.close_connections()

loop = asyncio.get_event_loop()
loop.run_until_complete(init())

This is the same problem on related models filters.

I was excepting a filtered queryset that contains only Tournament with bool_field value to True.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions