Skip to content

Commit 8b4712d

Browse files
authored
Merge pull request #17 from benavlabs/session-type-hint-fix
update type annotation from session to session generator
2 parents a26d11d + 5c703c0 commit 8b4712d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

crudadmin/admin_interface/crud_admin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import UTC, datetime, timedelta
66
from typing import (
77
Any,
8+
AsyncGenerator,
89
Dict,
910
List,
1011
Optional,
@@ -84,7 +85,7 @@ class CRUDAdmin:
8485
- Token-based authentication
8586
8687
Args:
87-
session: Async SQLAlchemy session for database operations
88+
session: Async SQLAlchemy session dependency function that yields sessions
8889
SECRET_KEY: Secret key for session management and cookie signing. Generate securely using:
8990
**Python one-liner (recommended)**
9091
python -c "import secrets; print(secrets.token_urlsafe(32))"
@@ -290,7 +291,7 @@ class OrderUpdate(BaseModel):
290291

291292
def __init__(
292293
self,
293-
session: AsyncSession,
294+
session: Callable[[], AsyncGenerator[AsyncSession, None]],
294295
SECRET_KEY: str,
295296
mount_path: Optional[str] = "/admin",
296297
theme: Optional[str] = "dark-theme",

crudadmin/core/db.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class DatabaseConfig:
5959
def __init__(
6060
self,
6161
base: Type[DeclarativeBase],
62-
session: AsyncSession,
62+
session: Callable[[], AsyncGenerator[AsyncSession, None]],
6363
admin_db_url: Optional[str] = None,
6464
admin_db_path: Optional[str] = None,
6565
admin_user: Optional[Type[DeclarativeBase]] = None,
@@ -88,7 +88,7 @@ def __init__(
8888
] = None,
8989
) -> None:
9090
self.base: Type[DeclarativeBase] = base
91-
self.session: AsyncSession = session
91+
self.session: Callable[[], AsyncGenerator[AsyncSession, None]] = session
9292

9393
if admin_db_url is None:
9494
if admin_db_path is None:
@@ -197,8 +197,8 @@ def get_admin_session(self) -> AsyncSession:
197197
"""Get a session for the admin database."""
198198
return self.admin_session
199199

200-
def get_app_session(self) -> AsyncSession:
201-
"""Get a session for the main application database."""
200+
def get_app_session(self) -> Callable[[], AsyncGenerator[AsyncSession, None]]:
201+
"""Get a session dependency for the main application database."""
202202
return self.session
203203

204204
def get_primary_key(self, model: Type[DeclarativeBase]) -> Optional[str]:

0 commit comments

Comments
 (0)