From c002327295b208d975281df67645602b2fb0ca5f Mon Sep 17 00:00:00 2001 From: grillazz Date: Sun, 18 Apr 2021 17:44:53 +0200 Subject: [PATCH] add type for get_db method --- the_app/database.py | 3 ++- the_app/models/stuff.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/the_app/database.py b/the_app/database.py index ba88a9d..4476436 100644 --- a/the_app/database.py +++ b/the_app/database.py @@ -1,3 +1,4 @@ +from typing import Generator from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker @@ -18,7 +19,7 @@ async_session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession # Dependency -async def get_db(): +async def get_db() -> Generator: session = async_session() try: yield session diff --git a/the_app/models/stuff.py b/the_app/models/stuff.py index b7ec3a7..cfe2a95 100644 --- a/the_app/models/stuff.py +++ b/the_app/models/stuff.py @@ -22,7 +22,8 @@ class Stuff(Base): async def find(cls, db_session: AsyncSession, name: str): stmt = select(cls).where(cls.name == name) result = await db_session.execute(stmt) - if instance := result.scalars().first() is None: + instance = result.scalars().first() + if instance is None: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail={"Record not found": f"There is no record for requested name value : {name}"},