feat(core): Upgrade pydantic to 2.x (#1428)

This commit is contained in:
Fangyin Cheng
2024-04-20 09:41:16 +08:00
committed by GitHub
parent baa1e3f9f6
commit 57be1ece18
103 changed files with 1146 additions and 534 deletions

View File

@@ -30,7 +30,7 @@ async def validation_exception_handler(
message += loc + ":" + error.get("msg") + ";"
res = Result.failed(msg=message, err_code="E0001")
logger.error(f"validation_exception_handler catch RequestValidationError: {res}")
return JSONResponse(status_code=400, content=res.dict())
return JSONResponse(status_code=400, content=res.to_dict())
async def http_exception_handler(request: Request, exc: HTTPException):
@@ -39,7 +39,7 @@ async def http_exception_handler(request: Request, exc: HTTPException):
err_code=str(exc.status_code),
)
logger.error(f"http_exception_handler catch HTTPException: {res}")
return JSONResponse(status_code=exc.status_code, content=res.dict())
return JSONResponse(status_code=exc.status_code, content=res.to_dict())
async def common_exception_handler(request: Request, exc: Exception) -> JSONResponse:
@@ -57,7 +57,7 @@ async def common_exception_handler(request: Request, exc: Exception) -> JSONResp
err_code="E0003",
)
logger.error(f"common_exception_handler catch Exception: {res}")
return JSONResponse(status_code=400, content=res.dict())
return JSONResponse(status_code=400, content=res.to_dict())
def add_exception_handler(app: "FastAPI"):

View File

@@ -2,12 +2,12 @@ from typing import Dict
import pytest
import pytest_asyncio
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from httpx import AsyncClient
from dbgpt.component import SystemApp
from dbgpt.util import AppConfig
from dbgpt.util.fastapi import create_app
def create_system_app(param: Dict) -> SystemApp:
@@ -17,7 +17,7 @@ def create_system_app(param: Dict) -> SystemApp:
elif not isinstance(app_config, AppConfig):
raise RuntimeError("app_config must be AppConfig or dict")
test_app = FastAPI()
test_app = create_app()
test_app.add_middleware(
CORSMiddleware,
allow_origins=["*"],