Troubleshooting¶
Common issues and their solutions for the QuoinAPI project.
Application Startup¶
"Database engine is not initialized"¶
Cause: The database engine wasn't created during app lifespan.
Solution: Ensure create_app() is used and the lifespan context
manager runs:
# Correct
from app.main import app # Uses create_app()
# Incorrect
app = FastAPI() # Missing lifespan
"FAILED: Target database is not up to date"¶
Cause: Database schema is behind the code.
Solution: Run pending migrations:
Database Issues¶
Connection Refused¶
Check:
- Is PostgreSQL running?
- Are
QUOIN_POSTGRES_*env vars correct?
- Is the port already in use?
"Async driver Required for Async Operations"¶
Cause: Using postgresql:// instead of postgresql+asyncpg://.
Solution: Check QUOIN_POSTGRES_DRIVER in .env:
Migration Conflicts¶
Cause: Git merge created conflicting migration files.
Solution:
- Check migration history:
-
Delete conflicting migrations (keep the correct one)
-
Regenerate if needed:
Testing Issues¶
"Fixture not found"¶
Cause: Missing import or fixture not in visible scope.
Solution: Check fixture is defined in conftest.py:
Tests Fail with "Event loop is closed"¶
Cause: Mixing sync and async test fixtures.
Solution: Use pytest-asyncio and mark tests async:
import pytest
@pytest.mark.asyncio
async def test_user_creation(client: AsyncClient):
response = await client.post("/api/v1/users/", ...)
Database State Leaks Between Tests¶
Cause: Transactions not rolled back.
Solution: Use session fixture that auto-rolls back:
@pytest.fixture
async def session(app) -> AsyncGenerator[AsyncSession, None]:
async with async_session() as session:
async with session.begin():
yield session
await session.rollback()
Development Server¶
Auto-reload Not Working¶
Cause: Running without --reload flag.
Solution: Use the just dev command:
Port Already in Use¶
Solution: Kill the process using port 8000:
Or change the port:
Documentation Build¶
"mkdocstrings plugin is enabled but not installed"¶
Solution: Install the docs dependencies:
Page Not Found in Navigation¶
Cause: File exists but not in zensical.toml nav.
Solution: Add page to navigation:
Dependency Management¶
"Package not found"¶
Solution: Clear cache and retry:
Lock File Out of Sync¶
Solution: Regenerate the lockfile:
Docker Issues¶
Build Fails: "No module named 'app'"¶
Cause: Source files not copied into the image.
Solution: Check Dockerfile has COPY commands:
Container Exits Immediately¶
Check logs:
Common causes:
- Database not accessible (check
DATABASE_URL) - Missing environment variables
- Migrations failed (run migrations manually)
Type Checking¶
"Incompatible types in assignment"¶
Cause: Function can return None but type hint doesn't allow it.
Solution: Add | None to return type:
async def get_user(user_id: UUID) -> User | None: # Allow None
return await self.session.get(User, user_id)
"Missing type parameters"¶
Solution: Add type parameters:
Performance¶
Slow Queries¶
Enable SQL echo to see queries:
# app/db/session.py
engine = create_async_engine(
str(settings.DATABASE_URL),
echo=True, # Print all SQL
)
Common fixes:
- Add database indexes
- Use
select_relatedfor joins - Paginate large result sets
High Memory Usage¶
Check:
- Connection pool size (default: 20):
-
Leaked sessions (use
async withcontext manager) -
Large result sets (add pagination)
Production Issues¶
500 Errors with No Logs¶
Cause: Exception not caught by app error handler.
Solution: Check exception type and add handler:
from fastapi import HTTPException
@app.exception_handler(HTTPException)
async def http_exception_handler(request, exc):
logger.error("http_error", status=exc.status_code, detail=exc.detail)
return JSONResponse(...)
OTEL Slowing Down Requests¶
Solution: Disable in development or reduce sampling:
Getting Help¶
If you're still stuck:
- Check logs:
docker-compose logsorjust devoutput - Search docs: Use the search bar in the documentation site
- Check GitHub Issues: Look for similar problems
- Review tests: See how the feature is tested in
tests/
Common Commands Reference¶
| Issue | Command |
|---|---|
| Start database | just db |
| Run migrations | just migrate-up |
| Run all checks | just check |
| Rebuild docs | just docb |
| View logs | docker-compose logs -f |
| Reset database | docker-compose down -v |
| Clean build artifacts | just clean |