-
-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
Summary
- After porting the implementation from sqlspec/docs/examples/frameworks/litestar/sqlite_app.py into the local
litestar-sqlspec-appproject, the application fails to resolve the injected SQLite session and raisesAttributeError: '_GeneratorContextManager' object has no attribute 'cursor'. - Although uv.lock within the sqlspec repo references Litestar 2.18.0, the container resolves Litestar 2.8.2, so version mismatches may be involved.
Environment
- Project:
litestar-sqlspec-app(Docker / Poetry) - Host OS: macOS
- Python: 3.12 (inside container)
- sqlspec: 0.29.0
- Litestar: 2.8.2 (confirmed with
poetry run python -c "import litestar; print(litestar.__version__)") - Docker Compose: Using the provided
docker-compose.yml
Main Packages
| Package | Version |
|---|---|
| Python | 3.12 |
| litestar | 2.8.2 |
| sqlspec | 0.29.0 |
| pydantic | 2.x |
| python-dotenv | 1.2.x |
| pytest | 8.4.x |
Steps to Reproduce
- Replicate sqlspec/docs/examples/frameworks/litestar/sqlite_app.py into app/lite.py:
- use SQLSpecPlugin
- call config.provide_session() in seed_database to create tables and seed demo data
- Run
docker-compose up --build - Access
http://localhost:8000/articles
Actual Behavior
A request triggers the following exception and returns HTTP 500:
AttributeError: '_GeneratorContextManager' object has no attribute 'cursor'
Excerpt from the full traceback:
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/sqlspec/driver/_sync.py", line 64, in dispatch_statement_execution
with self.handle_database_exceptions(), self.with_cursor(connection) as cursor:
File "/app/.venv/lib/python3.12/site-packages/sqlspec/adapters/sqlite/driver.py", line 85, in __enter__
self.cursor = self.connection.cursor()
AttributeError: '_GeneratorContextManager' object has no attribute 'cursor'
During handling of the above exception, another exception occurred:
...
File "/app/.venv/lib/python3.12/site-packages/sqlspec/extensions/litestar/handlers.py", line 66, in handler
await ensure_async_(connection.close)()
AttributeError: '_GeneratorContextManager' object has no attribute 'close'
Expected Behavior
- Litestar’s DI should provide a valid
SqliteDriver, andGET /articlesshould return a list of articles with 200 OK. - Behavior should match the official example.
Additional Context
- The official example keeps the synchronous code (with config.provide_session() as session:); I tried making seed_database async and using
async with, but the underlying error persists. - It appears sqlspec/extensions/litestar/plugin.py expects Litestar 2.18.0+, while the current environment resolves 2.8.2, which may cause DI behavior differences.
Willingness to Contribute / Needed Guidance
- If this is already known, I’m willing to work on a fix. Any guidance on where to look (e.g., Litestar DI changes, expected return values from provide_session) would be greatly appreciated.
- If there are reference materials or test cases that would help with debugging, please share them.
URL to code causing the issue
No response
MCVE
# Your MCVE code hereSteps to reproduce
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See errorScreenshots
"In the format of: "
Logs
Package Version
| Package | Version |
|---|---|
| Python | 3.12 |
| litestar | 2.8.2 |
| sqlspec | 0.29.0 |
| pydantic | 2.x |
| python-dotenv | 1.2.x |
| pytest | 8.4.x |
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working