From 02340f807d6185dfc3b279e0fbe9b11d51c42bc5 Mon Sep 17 00:00:00 2001 From: Vyacheslav Kapitonov Date: Tue, 14 Jul 2026 17:02:57 +0300 Subject: [PATCH 1/2] Migrate to Python 3.13 --- .github/workflows/testing.yaml | 2 +- Dockerfile | 2 +- bot/data/models.py | 8 ++++++-- requirements.txt | 2 +- tests/conftest.py | 16 +++++++++++----- tox.ini | 3 ++- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 4c4489f..77d43b0 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -10,4 +10,4 @@ jobs: main: uses: heyslava/workflows/.github/workflows/tox.yml@v0.3.0 with: - env: '["py311"]' + env: '["py313"]' diff --git a/Dockerfile b/Dockerfile index 3f32139..b6cc922 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim-bullseye +FROM python:3.13-slim-bullseye WORKDIR /app diff --git a/bot/data/models.py b/bot/data/models.py index cb4054f..3152384 100644 --- a/bot/data/models.py +++ b/bot/data/models.py @@ -26,6 +26,10 @@ class Base(DeclarativeBase): metadata = meta +def _utc_now() -> dt.datetime: + return dt.datetime.now(dt.timezone.utc).replace(tzinfo=None) + + class User(Base): __tablename__ = 'users' id: Mapped[int] = mapped_column(primary_key=True) @@ -63,11 +67,11 @@ class Expense(Base): comment: Mapped[str] = mapped_column(String, nullable=True) cdate: Mapped[dt.datetime] = mapped_column( DateTime, - default=dt.datetime.utcnow, + default=_utc_now, ) cdate_tz: Mapped[dt.datetime] = mapped_column( DateTime, - default=dt.datetime.utcnow, + default=_utc_now, nullable=True, ) is_replenishment: Mapped[bool] = mapped_column( diff --git a/requirements.txt b/requirements.txt index 80abbd9..29f5225 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ aiogram==3.19.0 alembic pydantic pytz -SQLAlchemy==2.0.30 +SQLAlchemy==2.0.51 diff --git a/tests/conftest.py b/tests/conftest.py index aa688cd..d1aa498 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,7 +17,10 @@ def engine(): tmpfile = Path(dir) / 'pytest.db' conn_str = f'sqlite:///{tmpfile}' engine = sa.create_engine(conn_str) - yield engine + try: + yield engine + finally: + engine.dispose() @pytest.fixture(scope='function') @@ -26,10 +29,13 @@ def db(engine): session: orm.Session = _factory() Base.metadata.create_all(bind=engine) - yield session - for table in reversed(Base.metadata.sorted_tables): - session.execute(table.delete()) - session.commit() + try: + yield session + finally: + for table in reversed(Base.metadata.sorted_tables): + session.execute(table.delete()) + session.commit() + session.close() @pytest.fixture(scope='function') diff --git a/tox.ini b/tox.ini index 60603ff..ba63fe4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -env_list = py311,pre-commit +env_list = py313,pre-commit [testenv] deps = @@ -17,6 +17,7 @@ commands = addopts = -ra -v + -W error testpaths = tests pythonpath = bot From ee2d5453cf3b255294d5eed62f73a956cd816464 Mon Sep 17 00:00:00 2001 From: Vyacheslav Kapitonov Date: Tue, 14 Jul 2026 17:10:06 +0300 Subject: [PATCH 2/2] Update reusable workflow to v1.3.0 for Python 3.13 support --- .github/workflows/testing.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 77d43b0..c25dc97 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -8,6 +8,6 @@ on: jobs: main: - uses: heyslava/workflows/.github/workflows/tox.yml@v0.3.0 + uses: heyslava/workflows/.github/workflows/tox.yml@v1.3.0 with: env: '["py313"]'