diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 693cd82f5..31baa8dbc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ Changelog * Annotations over joins now work correctly with ``values()`` & ``values_list()`` * Ensure ``GROUP BY`` precedes ``HAVING`` to ensure that filtering by aggregates work correctly. * Fix bug with join query with aggregation +* Cast ``BooleanField`` values correctly on SQLite & MySQL 0.16.1 ------ diff --git a/tests/fields/test_bool.py b/tests/fields/test_bool.py index 8ab92f298..6bd7605d8 100644 --- a/tests/fields/test_bool.py +++ b/tests/fields/test_bool.py @@ -11,8 +11,8 @@ async def test_empty(self): async def test_create(self): obj0 = await testmodels.BooleanFields.create(boolean=True) obj = await testmodels.BooleanFields.get(id=obj0.id) - self.assertEqual(obj.boolean, True) - self.assertEqual(obj.boolean_null, None) + self.assertIs(obj.boolean, True) + self.assertIs(obj.boolean_null, None) await obj.save() obj2 = await testmodels.BooleanFields.get(id=obj.id) self.assertEqual(obj, obj2) @@ -21,15 +21,15 @@ async def test_update(self): obj0 = await testmodels.BooleanFields.create(boolean=False) await testmodels.BooleanFields.filter(id=obj0.id).update(boolean=False) obj = await testmodels.BooleanFields.get(id=obj0.id) - self.assertEqual(obj.boolean, False) - self.assertEqual(obj.boolean_null, None) + self.assertIs(obj.boolean, False) + self.assertIs(obj.boolean_null, None) async def test_values(self): obj0 = await testmodels.BooleanFields.create(boolean=True) values = await testmodels.BooleanFields.get(id=obj0.id).values("boolean") - self.assertEqual(values[0]["boolean"], True) + self.assertIs(values[0]["boolean"], True) async def test_values_list(self): obj0 = await testmodels.BooleanFields.create(boolean=True) values = await testmodels.BooleanFields.get(id=obj0.id).values_list("boolean", flat=True) - self.assertEqual(values[0], True) + self.assertIs(values[0], True) diff --git a/tortoise/backends/asyncpg/executor.py b/tortoise/backends/asyncpg/executor.py index 2d7bfb569..8bfebcfa5 100644 --- a/tortoise/backends/asyncpg/executor.py +++ b/tortoise/backends/asyncpg/executor.py @@ -10,7 +10,7 @@ class AsyncpgExecutor(BaseExecutor): EXPLAIN_PREFIX = "EXPLAIN (FORMAT JSON, VERBOSE)" - DB_NATIVE = BaseExecutor.DB_NATIVE | {uuid.UUID} + DB_NATIVE = BaseExecutor.DB_NATIVE | {bool, uuid.UUID} def Parameter(self, pos: int) -> Parameter: return Parameter("$%d" % (pos + 1,)) diff --git a/tortoise/backends/base/executor.py b/tortoise/backends/base/executor.py index 5e4b804d8..933950c49 100644 --- a/tortoise/backends/base/executor.py +++ b/tortoise/backends/base/executor.py @@ -31,7 +31,7 @@ class BaseExecutor: TO_DB_OVERRIDE: Dict[Type[Field], Callable] = {} FILTER_FUNC_OVERRIDE: Dict[Callable, Callable] = {} EXPLAIN_PREFIX: str = "EXPLAIN" - DB_NATIVE = {bytes, str, int, bool, float, decimal.Decimal, datetime.datetime, datetime.date} + DB_NATIVE = {bytes, str, int, float, decimal.Decimal, datetime.datetime, datetime.date} def __init__( self, diff --git a/tortoise/backends/sqlite/executor.py b/tortoise/backends/sqlite/executor.py index bf9588320..8ef5a6fd1 100644 --- a/tortoise/backends/sqlite/executor.py +++ b/tortoise/backends/sqlite/executor.py @@ -57,7 +57,7 @@ class SqliteExecutor(BaseExecutor): fields.DatetimeField: to_db_datetime, } EXPLAIN_PREFIX = "EXPLAIN QUERY PLAN" - DB_NATIVE = {bytes, str, int, bool, float} + DB_NATIVE = {bytes, str, int, float} def Parameter(self, pos: int) -> Parameter: return Parameter("?")