mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
format and lint
This commit is contained in:
parent
e2f01f89c5
commit
700a2d49a6
@ -1,9 +1,9 @@
|
|||||||
from collections.abc import AsyncGenerator
|
from collections.abc import AsyncGenerator
|
||||||
|
|
||||||
|
from fastapi.exceptions import ResponseValidationError
|
||||||
from rotoger import AppStructLogger
|
from rotoger import AppStructLogger
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||||
from fastapi.exceptions import ResponseValidationError
|
|
||||||
|
|
||||||
from app.config import settings as global_settings
|
from app.config import settings as global_settings
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import orjson
|
import orjson
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
|
from fastapi.exceptions import ResponseValidationError
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from rotoger import AppStructLogger
|
from rotoger import AppStructLogger
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from fastapi.exceptions import ResponseValidationError
|
|
||||||
|
|
||||||
logger = AppStructLogger().get_logger()
|
logger = AppStructLogger().get_logger()
|
||||||
|
|
||||||
#TODO: add reasoning for this in readme plus higligh using re-raise in db session
|
|
||||||
|
# TODO: add reasoning for this in readme plus higligh using re-raise in db session
|
||||||
async def sqlalchemy_exception_handler(
|
async def sqlalchemy_exception_handler(
|
||||||
request: Request, exc: SQLAlchemyError
|
request: Request, exc: SQLAlchemyError
|
||||||
) -> JSONResponse:
|
) -> JSONResponse:
|
||||||
@ -32,7 +33,7 @@ async def sqlalchemy_exception_handler(
|
|||||||
|
|
||||||
|
|
||||||
async def response_validation_exception_handler(
|
async def response_validation_exception_handler(
|
||||||
request: Request, exc: ResponseValidationError
|
request: Request, exc: ResponseValidationError
|
||||||
) -> JSONResponse:
|
) -> JSONResponse:
|
||||||
request_path = request.url.path
|
request_path = request.url.path
|
||||||
try:
|
try:
|
||||||
@ -76,4 +77,6 @@ async def response_validation_exception_handler(
|
|||||||
def register_exception_handlers(app: FastAPI) -> None:
|
def register_exception_handlers(app: FastAPI) -> None:
|
||||||
"""Register all exception handlers with the FastAPI app."""
|
"""Register all exception handlers with the FastAPI app."""
|
||||||
app.add_exception_handler(SQLAlchemyError, sqlalchemy_exception_handler)
|
app.add_exception_handler(SQLAlchemyError, sqlalchemy_exception_handler)
|
||||||
app.add_exception_handler(ResponseValidationError, response_validation_exception_handler)
|
app.add_exception_handler(
|
||||||
|
ResponseValidationError, response_validation_exception_handler
|
||||||
|
)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from fastapi import HTTPException, status
|
|
||||||
from sqlalchemy import String, select
|
from sqlalchemy import String, select
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
@ -25,5 +24,3 @@ class Nonsense(Base):
|
|||||||
result = await db_session.execute(stmt)
|
result = await db_session.execute(stmt)
|
||||||
instance = result.scalars().first()
|
instance = result.scalars().first()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user