Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastAPI: passing SQLAlchemy Session through SlackRequestHandler #542

Closed
kafejo opened this issue Dec 10, 2021 · 2 comments · Fixed by #544
Closed

FastAPI: passing SQLAlchemy Session through SlackRequestHandler #542

kafejo opened this issue Dec 10, 2021 · 2 comments · Fixed by #544
Assignees
Labels
area:adapter enhancement New feature or request
Milestone

Comments

@kafejo
Copy link

kafejo commented Dec 10, 2021

In the FastAPI documentation they suggest to pass db session in following fashion:

@api.post("/slack/events")
async def endpoint(req: Request, db: Session = Depends(get_db)):
    return await app_handler.handle(req)

Is there suggested way to handle this? Couldn't find anything in documentation or examples and can't make it work.

See https://fastapi.tiangolo.com/tutorial/sql-databases/#create-a-dependency

Thanks for your help.

@kafejo kafejo changed the title FastAPI: passing SQLAlchemy through SlackRequestHandler FastAPI: passing SQLAlchemy Session through SlackRequestHandler Dec 10, 2021
@seratch seratch added area:adapter enhancement New feature or request labels Dec 12, 2021
@seratch seratch added this to the 1.11.0 milestone Dec 12, 2021
@seratch seratch self-assigned this Dec 12, 2021
seratch added a commit to seratch/bolt-python that referenced this issue Dec 12, 2021
@seratch
Copy link
Member

seratch commented Dec 12, 2021

Hi @kafejo, thanks for taking the time to write in!

The only solution that I can think of is to enable context objects to include the additional values this way: #544 With the solution, you can pass the db object as below:

@api.post("/slack/events")
async def endpoint(req: Request, db: Session = Depends(get_db)):
    return await app_handler.handle(req, {"db": db})

Your listeners/middleware can access the "db" data by context.get("db") method call.

Let us know if you have any different suggestions for better support of the use case.

seratch added a commit to seratch/bolt-python that referenced this issue Dec 13, 2021
@kafejo
Copy link
Author

kafejo commented Dec 13, 2021

Amazing, thanks for the quick response and solution! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:adapter enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants