Help in connecting Neon db with DatabaseSessionService in google adk

The Problem:
I keep getting this error when trying to set up my database connection:

greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place? (Background on this error at: https://sqlalche.me/e/20/xd2s)
My Setup:
I'm using DatabaseSessionService with a Neon Cloud Database (PostgreSQL). Here's what my code looks like:

DB_URL = "postgres+asyncpg://user:password@your-neon-hostname.neon.tech/neondb"

Create a lifespan event to initialize and clean up the session service

@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup code
print("Application starting up...")

# Initialize the DatabaseSessionService instance and store it in app.state
try:
app.state.session_service = DatabaseSessionService(
db_url=DB_URL,
connect_args={"ssl": "require"}
)
print("Database session service initialized successfully.")
except Exception as e:
print("Database session service initialization failed.")
print(e)

yield

# Shutdown code
print("Application shutting down...")

app = FastAPI(title="ADK Multi-Agent FastAPI Demo", lifespan=lifespan)
Was this page helpful?