Skip to content

Commit feca831

Browse files
Upgrade aiohttp (#9348)
* Upgrade aiohttp * Update aiohttp.dockerfile * Update aiohttp-pg-raw.dockerfile * Update aiohttp-pg-raw.dockerfile * Update main.py * Update models.py * Update frameworks/Python/aiohttp/requirements.txt * Update models.py * Update aiohttp.dockerfile * Update aiohttp-pg-raw.dockerfile * Update requirements.txt * Update requirements.txt * Update requirements.txt * Update aiohttp-pg-raw.dockerfile * Update aiohttp.dockerfile * Update main.py * Update requirements.txt * Update aiohttp-pg-raw.dockerfile * Update aiohttp.dockerfile
1 parent 05ad8ef commit feca831

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
FROM python:3.8
1+
FROM python:3.13
22

33
ADD ./ /aiohttp
44

55
WORKDIR aiohttp
66

7-
RUN pip3 install cython==0.29.23 && \
7+
RUN pip3 install cython==3.0.11 && \
88
pip3 install -r /aiohttp/requirements.txt
99

1010
ENV CONNECTION=RAW
1111

1212
EXPOSE 8080
1313

14-
CMD gunicorn app.gunicorn:app -c gunicorn_conf.py
14+
CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
FROM python:3.8
1+
FROM python:3.13
22

33
ADD ./ /aiohttp
44

55
WORKDIR aiohttp
66

7-
RUN pip3 install cython==0.29.23 && \
7+
RUN pip3 install cython==3.0.11 && \
88
pip3 install -r /aiohttp/requirements.txt
99

1010
WORKDIR /aiohttp
1111

1212
EXPOSE 8080
1313

14-
CMD gunicorn app.gunicorn:app -c gunicorn_conf.py
14+
CMD python3 -O -m gunicorn app.gunicorn:app -c gunicorn_conf.py

frameworks/Python/aiohttp/app/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import asyncpg
55
from aiohttp import web
66
from sqlalchemy.engine.url import URL
7-
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
8-
from sqlalchemy.orm import sessionmaker
7+
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
98

109
from .views import (
1110
json,
@@ -28,14 +27,15 @@ def pg_dsn(dialect=None) -> str:
2827
"""
2928
:return: DSN url suitable for sqlalchemy and aiopg.
3029
"""
31-
return str(URL.create(
30+
url = URL.create(
3231
database='hello_world',
3332
password=os.getenv('PGPASS', 'benchmarkdbpass'),
3433
host='tfb-database',
3534
port='5432',
3635
username=os.getenv('PGUSER', 'benchmarkdbuser'),
3736
drivername='postgresql+{}'.format(dialect) if dialect else 'postgresql',
38-
))
37+
)
38+
return url.render_as_string(hide_password=False)
3939

4040

4141
async def db_ctx(app: web.Application):
@@ -48,15 +48,17 @@ async def db_ctx(app: web.Application):
4848
print(f'connection pool: min size: {min_size}, max size: {max_size}, orm: {CONNECTION_ORM}')
4949
if CONNECTION_ORM:
5050
dsn = pg_dsn('asyncpg')
51-
engine = create_async_engine(dsn, future=True, pool_size=max_size)
52-
app['db_session'] = sessionmaker(engine, class_=AsyncSession)
51+
engine = create_async_engine(dsn, pool_size=max_size)
52+
app['db_session'] = async_sessionmaker(engine)
5353
else:
5454
dsn = pg_dsn()
5555
app['pg'] = await asyncpg.create_pool(dsn=dsn, min_size=min_size, max_size=max_size, loop=app.loop)
5656

5757
yield
5858

59-
if not CONNECTION_ORM:
59+
if CONNECTION_ORM:
60+
await app['db_session'].dispose()
61+
else:
6062
await app['pg'].close()
6163

6264

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
from sqlalchemy import Column, Integer, String
2-
from sqlalchemy.ext.declarative import declarative_base
1+
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
32

4-
Base = declarative_base()
3+
class Base(DeclarativeBase):
4+
"""Base for models."""
55

66

77
class World(Base):
88
__tablename__ = 'world'
9-
id = Column(Integer, primary_key=True)
10-
randomnumber = Column(Integer)
9+
id: Mapped[int] = mapped_column(primary_key=True)
10+
randomnumber: Mapped[int]
1111

1212
sa_worlds = World.__table__
1313

1414

1515
class Fortune(Base):
1616
__tablename__ = 'fortune'
17-
id = Column(Integer, primary_key=True)
18-
message = Column(String)
17+
id: Mapped[int] = mapped_column(primary_key=True)
18+
message: Mapped[str]
1919

2020
sa_fortunes = Fortune.__table__
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
aiohttp==3.10.2
2-
asyncpg==0.25.0
3-
cchardet==2.1.7
4-
gunicorn==20.1
5-
jinja2==3.1.4
6-
psycopg2==2.9.2
7-
SQLAlchemy==1.4.29
8-
ujson==5.4.0
9-
uvloop==0.16
1+
aiohttp==3.11.14
2+
asyncpg==0.30.0
3+
gunicorn==23.0.0
4+
jinja2==3.1.5
5+
psycopg2==2.9.10
6+
SQLAlchemy==2.0.39
7+
ujson==5.10.0
8+
uvloop==0.21.0

0 commit comments

Comments
 (0)