Skip to content

Commit 9ae7a8c

Browse files
* fix: fix logging backported 06710cc
1 parent d20b6c4 commit 9ae7a8c

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313
strategy:
1414
max-parallel: 4
1515
matrix:

peewee_async/databases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def aio_connection(self) -> ConnectionContextManager:
122122
return ConnectionContextManager(self.pool_backend)
123123

124124
async def aio_execute_sql(self, sql: str, params=None, fetch_results=None):
125-
__log__.debug(sql, params)
125+
__log__.debug((sql, params))
126126
with peewee.__exception_wrapper__:
127127
async with self.aio_connection() as connection:
128128
async with connection.cursor() as cursor:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "peewee-async"
3-
version = "0.12.0"
3+
version = "0.12.2"
44
description = "Asynchronous interface for peewee ORM powered by asyncio."
55
authors = ["Alexey Kinev <[email protected]>", "Gorshkov Nikolay(contributor) <[email protected]>"]
66
readme = "README.md"

tests/conftest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import asyncio
2+
import logging
3+
from typing import Generator
24

35
import pytest
46
from peewee import sort_models
@@ -8,6 +10,19 @@
810
from peewee_async.utils import aiopg, aiomysql
911

1012

13+
@pytest.fixture
14+
def enable_debug_log_level() -> Generator[None, None, None]:
15+
logger = logging.getLogger('peewee.async')
16+
handler = logging.StreamHandler()
17+
logger.addHandler(handler)
18+
logger.setLevel(logging.DEBUG)
19+
20+
yield
21+
22+
logger.removeHandler(handler)
23+
logger.setLevel(logging.INFO)
24+
25+
1126
@pytest.fixture(scope="session", autouse=True)
1227
def event_loop():
1328
loop = asyncio.get_event_loop_policy().new_event_loop()
@@ -59,6 +74,3 @@ async def db(request):
5974
dbs_all = pytest.mark.parametrize(
6075
"db", PG_DBS + MYSQL_DBS, indirect=["db"]
6176
)
62-
63-
64-

tests/test_common.py

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

44
import peewee
55
import pytest
6+
from pytest import LogCaptureFixture
67

8+
from peewee_async.databases import AioDatabase
79
from tests.conftest import dbs_all
810
from tests.db_config import DB_CLASSES, DB_DEFAULTS
911
from tests.models import TestModel, CompositeTestModel
@@ -89,3 +91,13 @@ async def test_allow_sync_is_reverted_for_exc(db):
8991
except peewee.IntegrityError:
9092
pass
9193
assert db._allow_sync is False
94+
95+
96+
@dbs_all
97+
async def test_logging(db: AioDatabase, caplog: LogCaptureFixture, enable_debug_log_level: None) -> None:
98+
99+
await TestModel.aio_create(text="Test 1")
100+
101+
assert 'INSERT INTO' in caplog.text
102+
assert 'testmodel' in caplog.text
103+
assert 'VALUES' in caplog.text

0 commit comments

Comments
 (0)