-
Notifications
You must be signed in to change notification settings - Fork 28
Session manager will always use memory for admin session storage #37
Copy link
Copy link
Closed
Description
I have tried to make the package use redis and postgres and in both cases it was uses memory instead, after tracing this issue i found that session_manager is initialized and never changes after using session_manager.
minimal code to reproduce
from contextlib import asynccontextmanager
from typing import AsyncGenerator
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import configure_mappers
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/testdb"
engine = create_async_engine(DATABASE_URL)
async_engine = create_async_engine(DATABASE_URL, echo=False, future=True)
local_session = async_sessionmaker(
bind=async_engine, class_=AsyncSession, expire_on_commit=False
)
from crudadmin import CRUDAdmin
app = FastAPI()
# Create database session dependency
async def get_session() -> AsyncGenerator[AsyncSession, None]:
async with local_session() as session:
yield session
# # Create admin interface
admin = CRUDAdmin(
session=get_session,
SECRET_KEY="your-secret-key-here",
initial_admin={"username": "admin", "password": "secure_password123"},
secure_cookies=False,
).use_redis_sessions(redis_url="redis://localhost:6379/0")
admin_storage = admin.session_manager.storage
print("Admin storage initialized:", admin_storage)
@asynccontextmanager
async def lifespan(app: FastAPI):
await admin.initialize()
yield
# Create and mount the app
app = FastAPI(lifespan=lifespan)
app.mount("/admin", admin.app)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
here the output should be RedisSessionStorage instead of MemorySessionStorage

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels