Asynchronous sessionmaker initialization type error
See original GitHub issueDescribe the bug mypy fails on asynchronous sessionmaker initialization.
Expected behavior No errors.
To Reproduce Please try to provide a Minimal, Complete, and Verifiable example. See also Reporting Bugs on the website, and some example issues.
Please do not use Flask-SQLAlchemy or any other third-party extensions or dependencies in test cases. The test case must illustrate the problem without using any third party SQLAlchemy extensions. Otherwise, please report the bug to those projects first.
import os
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import sessionmaker
engine = create_async_engine(os.getenv("DATABASE_URL"))
async_session = sessionmaker(engine, class_=AsyncSession)
Error
session.py:8: error: Value of type variable "_TSessionMakerType" of "sessionmaker" cannot be "AsyncSession"
Found 1 error in 1 file (checked 1 source file)
Versions.
- OS: Linux
- Python: 3.9.6
- SQLAlchemy: 1.4.23
- mypy: 0.910
- SQLAlchemy2-stubs: v0.0.2a9
Additional context The problem appeared on the latest release of sqlalchemy2-stubs and was not present on v0.0.2a8.
Have a nice day!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Asynchronous I/O (asyncio) - SQLAlchemy 1.4 Documentation
This is useful when initializing a series of objects which involve existing database queries, where the uncompleted object should not yet be ...
Read more >Correct usage of session with asynchronous servers in ...
Background: We have a Python web application which uses SqlAlchemy as ORM. We run this application with Gunicorn(sync worker) currently. This ...
Read more >Async SQLAlchemy with FastAPI
In base.py we will initialize the new SQLAlchemy engine with create_async_engine() and create an async session maker by passing it the new ...
Read more >Async SqlAlchemy with FastAPI: Getting single session for all ...
The problem appears when I try to execute multiple requests, an error appears that seems to indicate that the same session is being...
Read more >FastAPI with Async SQLAlchemy, SQLModel, and Alembic
SQLModel. Next, let's add SQLModel, a library for interacting with SQL databases from Python code, with Python objects. Based on Python type ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mjpieters I am hoping 2.0 betas are very soon. that’s where these issues if you have them will be permanently fixed so i hope you have time to test a bit.
This appears to have regressed? I’m using version 0.0.2a27, and the example in this issue now produces:
when using Pyright.
I noticed that almost the same error message appears when using
sqlalchemy.create_engine()
andsqlalchemy.orm.Session
: