MCPcopy
hub / github.com/Agenta-AI/agenta / get_core_session

Method get_core_session

api/oss/src/models/db/postgres_engine.py:67–90  ·  view source on GitHub ↗

Async context manager to yield a database session. This context manager ensures that any changes made during the session are rolled back in case of an exception, and the session is properly closed to prevent memory leaks. Yields: AsyncSession: S

(self)

Source from the content-addressed store, hash-verified

65
66 @asynccontextmanager
67 async def get_core_session(self) -> AsyncGenerator[AsyncSession, None]:
68 """
69 Async context manager to yield a database session.
70
71 This context manager ensures that any changes made during the session are
72 rolled back in case of an exception, and the session is properly closed to
73 prevent memory leaks.
74
75 Yields:
76 AsyncSession: SQLAlchemy async session for database operations.
77
78 Raises:
79 Exception: Any exception that occurs within the context will be
80 re-raised after the session rollback.
81 """
82
83 session = self.async_core_session()
84 try:
85 yield session
86 except Exception as e:
87 await session.rollback()
88 raise e
89 finally:
90 await session.close()
91
92 @asynccontextmanager
93 async def get_tracing_session(self) -> AsyncGenerator[AsyncSession, None]:

Callers 5

createMethod · 0.80
getMethod · 0.80
listMethod · 0.80
updateMethod · 0.80
deleteMethod · 0.80

Calls 1

closeMethod · 0.80

Tested by

no test coverage detected