Does graphene_sqlalchemy keep sessions open?
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
調査の方向性
まず、使い捨ての Postgres コンテナに対して reset_testdata()、close_all_sessions()、metadata.drop_all()/create_all() を使い、pytest のハングを再現します。示されている FastAPI ミドルウェアありの場合となしの場合で、graphene_sqlalchemy を使ったリクエストを比較し、その後セッションのライフサイクルを追跡します。セッションが残り続ける原因を特定し、期待されるクリーンアップ動作を文書化するか、リグレッションテストでカバーできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
tl;dr
Does graphene_sqlalchemy keep sessions open? I'm having the problem that Postgres doesnt run drop_all() in my test suite.
Explanation
Hi, I have a fastAPI app and I'm using graphene_sqlalchemy to generate an API from database models defined on the declarative base of SQLAlchemy. The database is postgres. For testing I am running some pytests against the API while it's running. So, I start a throw-away postgres container, then I start the API app, then I run pytest.
The tests include a reset_testdata() function which also uses the SQLAlchemy ORM. It looks like:
def reset_testdata():
close_all_sessions() # from sqlalchemy.orm.session
models.Base.metadata.drop_all(bind=engine)
models.Base.metadata.create_all(bind=engine)
db.add_all([
# ... add stuff
])
db.commit()
db.close()
I noticed, that once reset_testdata() is used, the pytest process hangs. No errors, not able to Ctrl+C, it just waits. I had this issue before and it usually stems from Postgres not allowing stuff like drop_all() if there are still active sessions. After some trying out I found that queries from my app (which are implemented by graphene_sqlalchemy) seem to keep a session open.
(I used this example in my app: https://docs.graphene-python.org/projects/sqlalchemy/en/latest/tutorial/#defining-our-models)
I tested this, and basically I can circumvent this problem by adding a middleware that closes all sessions after every request.
@app.middleware('http')
async def close_sessions(request: Request, call_next):
try:
response = await call_next(request)
finally:
close_all_sessions()
return response
I wonder whether I am missing something here? Any experience with this issue (if it is even an issue)?
- 主要言語
- Python
- スター
- 985
- フォーク
- 224
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql-python/graphene-sqlalchemy のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
graphql-python/graphene-sqlalchemy#422 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
graphql-python/graphene-sqlalchemy#419 · コメント 3 件 ·
graphql-python/graphene-sqlalchemy の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
anthropics/skills#1811 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
speaches-ai/speaches#678 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
datalayer/mcp-compose#42 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
conda-forge/spacy-feedstock#177 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
UKGovernmentBEIS/inspect_evals#2523 ·