Skip to content

Commit d9baef0

Browse files
committed
backend: remove deprecation warnings
1 parent 2f212c7 commit d9baef0

File tree

4 files changed

+43
-47
lines changed

4 files changed

+43
-47
lines changed

backend/app/crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ async def create_benchmark_result(
257257
allocation_histogram=result.result_json.allocation_histogram,
258258
total_allocated_bytes=result.result_json.total_allocated_bytes,
259259
top_allocating_functions=[
260-
func.dict() for func in result.result_json.top_allocating_functions
260+
func.model_dump() for func in result.result_json.top_allocating_functions
261261
],
262262
flamegraph_html=result.flamegraph_html,
263263
)

backend/app/factory.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import uuid
44
import time
55
import logging
6+
from contextlib import asynccontextmanager
7+
from typing import AsyncIterator
68
from fastapi import FastAPI, Request
79
from fastapi.middleware.cors import CORSMiddleware
810

@@ -31,13 +33,44 @@ def create_app(settings=None) -> FastAPI:
3133
if settings is None:
3234
settings = get_settings()
3335

36+
@asynccontextmanager
37+
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
38+
# Configure logging using the app state before the app starts serving.
39+
app.state.logging_manager.configure_logging()
40+
41+
# Disable uvicorn access logs to avoid duplication
42+
uvicorn_logger = logging.getLogger("uvicorn.access")
43+
uvicorn_logger.disabled = True
44+
45+
logger = get_logger("api.startup")
46+
logger.info(
47+
"Application starting up",
48+
extra={
49+
"log_level": settings.log_level,
50+
"log_format": settings.log_format,
51+
"api_version": settings.api_version,
52+
},
53+
)
54+
await create_tables()
55+
logger.info("Database tables created successfully")
56+
57+
# Ensure initial admin user exists
58+
from .database import AsyncSessionLocal
59+
from .crud import ensure_initial_admin
60+
61+
async with AsyncSessionLocal() as db:
62+
await ensure_initial_admin(db, settings.admin_initial_username)
63+
64+
yield
65+
3466
# Create FastAPI instance
3567
app = FastAPI(
3668
title=settings.api_title,
3769
version=settings.api_version,
3870
docs_url="/api/docs",
3971
redoc_url="/api/redoc",
4072
openapi_url="/api/openapi.json",
73+
lifespan=lifespan,
4174
)
4275

4376
# Store dependencies in app state
@@ -133,35 +166,6 @@ async def log_requests(request: Request, call_next):
133166

134167
return response
135168

136-
# Configure startup event
137-
@app.on_event("startup")
138-
async def startup_event():
139-
# Configure logging using the app state
140-
app.state.logging_manager.configure_logging()
141-
142-
# Disable uvicorn access logs to avoid duplication
143-
uvicorn_logger = logging.getLogger("uvicorn.access")
144-
uvicorn_logger.disabled = True
145-
146-
logger = get_logger("api.startup")
147-
logger.info(
148-
"Application starting up",
149-
extra={
150-
"log_level": settings.log_level,
151-
"log_format": settings.log_format,
152-
"api_version": settings.api_version,
153-
},
154-
)
155-
await create_tables()
156-
logger.info("Database tables created successfully")
157-
158-
# Ensure initial admin user exists
159-
from .database import AsyncSessionLocal
160-
from .crud import ensure_initial_admin
161-
162-
async with AsyncSessionLocal() as db:
163-
await ensure_initial_admin(db, settings.admin_initial_username)
164-
165169
# Include routers
166170
app.include_router(health.router)
167171
app.include_router(commits.router)

backend/app/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
Boolean,
1212
UniqueConstraint,
1313
)
14-
from sqlalchemy.ext.declarative import declarative_base
15-
from sqlalchemy.orm import relationship
14+
from sqlalchemy.orm import declarative_base, relationship
1615
from datetime import datetime, UTC
1716

1817
Base = declarative_base()

backend/app/schemas.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel
1+
from pydantic import BaseModel, ConfigDict
22
from typing import List, Optional, Dict, Any, Tuple
33
from datetime import datetime
44

@@ -22,8 +22,7 @@ class CommitCreate(CommitBase):
2222

2323

2424
class Commit(CommitBase):
25-
class Config:
26-
from_attributes = True
25+
model_config = ConfigDict(from_attributes=True)
2726

2827

2928
class BinaryBase(BaseModel):
@@ -45,8 +44,7 @@ class BinaryCreate(BinaryBase):
4544

4645

4746
class Binary(BinaryBase):
48-
class Config:
49-
from_attributes = True
47+
model_config = ConfigDict(from_attributes=True)
5048

5149

5250
class EnvironmentBase(BaseModel):
@@ -60,8 +58,7 @@ class EnvironmentCreate(EnvironmentBase):
6058

6159

6260
class Environment(EnvironmentBase):
63-
class Config:
64-
from_attributes = True
61+
model_config = ConfigDict(from_attributes=True)
6562

6663

6764
class RunBase(BaseModel):
@@ -78,8 +75,7 @@ class RunCreate(RunBase):
7875

7976

8077
class Run(RunBase):
81-
class Config:
82-
from_attributes = True
78+
model_config = ConfigDict(from_attributes=True)
8379

8480

8581
class TopAllocatingFunction(BaseModel):
@@ -111,8 +107,7 @@ class BenchmarkResultCreate(BaseModel):
111107

112108

113109
class BenchmarkResult(BenchmarkResultBase):
114-
class Config:
115-
from_attributes = True
110+
model_config = ConfigDict(from_attributes=True)
116111

117112

118113
# Worker upload schemas
@@ -181,8 +176,7 @@ class AdminUserPublic(BaseModel):
181176
added_at: datetime
182177
is_active: bool
183178

184-
class Config:
185-
from_attributes = True
179+
model_config = ConfigDict(from_attributes=True)
186180

187181

188182
class MemrayFailureReport(BaseModel):
@@ -204,5 +198,4 @@ class MemrayFailurePublic(BaseModel):
204198
failure_timestamp: datetime
205199
commit_timestamp: datetime
206200

207-
class Config:
208-
from_attributes = True
201+
model_config = ConfigDict(from_attributes=True)

0 commit comments

Comments
 (0)