Skip to content

Commit ff96197

Browse files
committed
fixing inconsistency between sqlite and postgres - exists() now returns True instead of just truthy values
1 parent 87a1cc8 commit ff96197

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

piccolo/query/methods/exists.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def where(self, where: Combinable) -> Exists:
2525
return self
2626

2727
async def response_handler(self, response) -> bool:
28-
return response[0]["exists"]
28+
# Convert to a bool - postgres returns True, and sqlite return 1.
29+
return bool(response[0]["exists"])
2930

3031
@property
3132
def querystrings(self) -> t.Sequence[QueryString]:

tests/table/test_exists.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44

55
class TestExists(DBTestCase):
6-
76
def test_exists(self):
87
self.insert_rows()
98

10-
response = Band.exists().where(
11-
Band.name == 'Pythonistas'
12-
).run_sync()
9+
response = Band.exists().where(Band.name == "Pythonistas").run_sync()
1310

14-
self.assertTrue(response == True)
11+
self.assertTrue(response is True)

0 commit comments

Comments
 (0)