From d82d43c09420dc49c9387db3a55da611e3ca89b1 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Fri, 29 Mar 2024 10:03:50 -0400 Subject: [PATCH] Fix boolean transformer for falsey values. It's best to be explicit when checking for None, otherwise 0 and False will count as None. --- pgsqlite/pgsqlite.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pgsqlite/pgsqlite.py b/pgsqlite/pgsqlite.py index 18b2e1c..af547ee 100644 --- a/pgsqlite/pgsqlite.py +++ b/pgsqlite/pgsqlite.py @@ -146,12 +146,12 @@ async def sem_task(coro): return await asyncio.gather(*(sem_task(coro) for coro in coros)) def boolean_transformer(self, val: Any, nullable: bool) -> Union[bool, None]: - if nullable and not val: + if nullable and val is None: return None - if not nullable and not val: + if not nullable and val is None: raise Exception("Value is None but column is not nullable") - if val == 1 or val.lower() == "true": + if val == 1 or str(val).lower() == "true": return "TRUE" return "FALSE"