fix: remove double-call on AsyncSession in SerieScanner
get_async_session_factory() returns session directly, not factory. Calling result again with () caused 'AsyncSession' object is not callable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -181,6 +181,22 @@ scheduler = AsyncIOScheduler(jobstores=jobstores)
|
||||
|
||||
**If server is down >1 hour:** No automatic recovery. Manual trigger via `POST /api/scheduler/trigger-rescan` or wait for next scheduled run.
|
||||
|
||||
### Database Session Management
|
||||
|
||||
`get_async_session_factory()` returns a **new AsyncSession instance** directly (not a factory). The function name is historical — callers receive the session immediately:
|
||||
|
||||
```python
|
||||
# Correct usage:
|
||||
db = get_async_session_factory() # db IS the session
|
||||
await db.execute(...)
|
||||
await db.commit()
|
||||
await db.close()
|
||||
```
|
||||
|
||||
Do NOT call the result again with `()` — that tries to call an `AsyncSession` object, causing `'AsyncSession' object is not callable`.
|
||||
|
||||
For context manager usage, prefer `get_db_session()` (auto-commits) or `get_transactional_session()` (manual commit).
|
||||
|
||||
### Health Check Endpoints
|
||||
|
||||
The application provides health check endpoints for monitoring and container orchestration:
|
||||
|
||||
@@ -218,8 +218,7 @@ class SerieScanner:
|
||||
try:
|
||||
from src.server.database.connection import get_async_session_factory
|
||||
|
||||
session_factory = get_async_session_factory()
|
||||
db = session_factory()
|
||||
db = get_async_session_factory()
|
||||
try:
|
||||
existing = await AnimeSeriesService.get_by_key(db, serie.key)
|
||||
if existing:
|
||||
|
||||
@@ -209,7 +209,7 @@ class TestPersistSerieToDbErrorHandling:
|
||||
|
||||
with patch(
|
||||
"src.server.database.connection.get_async_session_factory",
|
||||
return_value=mock_factory
|
||||
return_value=mock_session
|
||||
):
|
||||
with patch(
|
||||
"src.server.database.service.AnimeSeriesService.get_by_key",
|
||||
|
||||
Reference in New Issue
Block a user