Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backported 06710cc33c8b8d21fc522865ba0b861d1ffd2a5c to v0.12 #301

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
max-parallel: 4
matrix:
Expand Down
2 changes: 1 addition & 1 deletion peewee_async/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def aio_connection(self) -> ConnectionContextManager:
return ConnectionContextManager(self.pool_backend)

async def aio_execute_sql(self, sql: str, params=None, fetch_results=None):
__log__.debug(sql, params)
__log__.debug((sql, params))
with peewee.__exception_wrapper__:
async with self.aio_connection() as connection:
async with connection.cursor() as cursor:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "peewee-async"
version = "0.12.0"
version = "0.12.2"
description = "Asynchronous interface for peewee ORM powered by asyncio."
authors = ["Alexey Kinev <[email protected]>", "Gorshkov Nikolay(contributor) <[email protected]>"]
readme = "README.md"
Expand Down
18 changes: 15 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import logging
from typing import Generator

import pytest
from peewee import sort_models
Expand All @@ -8,6 +10,19 @@
from peewee_async.utils import aiopg, aiomysql


@pytest.fixture
def enable_debug_log_level() -> Generator[None, None, None]:
logger = logging.getLogger('peewee.async')
handler = logging.StreamHandler()
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

yield

logger.removeHandler(handler)
logger.setLevel(logging.INFO)


@pytest.fixture(scope="session", autouse=True)
def event_loop():
loop = asyncio.get_event_loop_policy().new_event_loop()
Expand Down Expand Up @@ -59,6 +74,3 @@ async def db(request):
dbs_all = pytest.mark.parametrize(
"db", PG_DBS + MYSQL_DBS, indirect=["db"]
)



12 changes: 12 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import peewee
import pytest
from pytest import LogCaptureFixture

from peewee_async.databases import AioDatabase
from tests.conftest import dbs_all
from tests.db_config import DB_CLASSES, DB_DEFAULTS
from tests.models import TestModel, CompositeTestModel
Expand Down Expand Up @@ -89,3 +91,13 @@ async def test_allow_sync_is_reverted_for_exc(db):
except peewee.IntegrityError:
pass
assert db._allow_sync is False


@dbs_all
async def test_logging(db: AioDatabase, caplog: LogCaptureFixture, enable_debug_log_level: None) -> None:

await TestModel.aio_create(text="Test 1")

assert 'INSERT INTO' in caplog.text
assert 'testmodel' in caplog.text
assert 'VALUES' in caplog.text
Loading