Skip to content

Commit 10efa3e

Browse files
committed
Fix #525 -- Unpack SQL arguments
Fix a TypeError when calling cursor.execute, we need to pass the query as attributes not as a single tuple.
1 parent 842bac0 commit 10efa3e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

health_check/contrib/db_heartbeat/backends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def check_status(self):
2323
result = None
2424
compiler = connection.ops.compiler("SQLCompiler")(SelectOne(), connection, None)
2525
with connection.cursor() as cursor:
26-
cursor.execute(compiler.compile(SelectOne()))
26+
cursor.execute(*compiler.compile(SelectOne()))
2727
result = cursor.fetchone()
2828

2929
if result != (1,):

tests/test_db_heartbeat.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import unittest
22
from unittest.mock import MagicMock, patch
33

4+
import pytest
5+
46
from health_check.contrib.db_heartbeat.backends import DatabaseHeartBeatCheck, SelectOne
57
from health_check.exceptions import ServiceUnavailable
68

@@ -20,8 +22,13 @@ def test_as_oracle(self):
2022

2123

2224
class TestDatabaseHeartBeatCheck(unittest.TestCase):
25+
@pytest.mark.django_db
26+
def test_check_status__success(self):
27+
health_check = DatabaseHeartBeatCheck()
28+
health_check.check_status()
29+
2330
@patch("health_check.contrib.db_heartbeat.backends.connection")
24-
def test_check_status_success(self, mock_connection):
31+
def test_check_status__failure(self, mock_connection):
2532
mock_cursor = MagicMock()
2633
mock_cursor.fetchone.return_value = (1,)
2734
mock_connection.cursor.return_value.__enter__.return_value = mock_cursor

0 commit comments

Comments
 (0)