Does graphene_sqlalchemy keep sessions open?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện hiện tượng pytest bị treo với reset_testdata(), close_all_sessions() và metadata.drop_all()/create_all() trên container Postgres dùng một lần. So sánh các request sử dụng graphene_sqlalchemy có và không có FastAPI middleware được nêu, sau đó lần theo vòng đời của session. Công việc được xem là hoàn tất khi đã xác định nguyên nhân của session còn tồn tại và hành vi cleanup dự kiến được ghi lại hoặc được bao phủ bằng một regression test.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)?
- Ngôn ngữ chính
- Python
- Star
- 985
- Fork
- 224
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của graphql-python/graphene-sqlalchemy
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
graphql-python/graphene-sqlalchemy#422 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
graphql-python/graphene-sqlalchemy#419 · 3 bình luận ·
Tất cả issue của graphql-python/graphene-sqlalchemy
Issue tương tự
-
essnmx good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
[Feature] 奇物选择添加优先级 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
syfoud/Simulated_Scepter#174 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Giskard-AI/giskard-oss#2840 · 1 bình luận ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Đang mởarea: repo bug perceived difficulty: 2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
yeti-platform/yeti#1380 ·