question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request object isn't passed as argument

See original GitHub issue

Thanks for this package. I have created graphql app using template but getting below error. It seems fastapi doesn’t pass request object.

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 184, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 261, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 146, in __call__
    await self.app(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/starlette/exceptions.py", line 58, in __call__
    await self.app(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 656, in __call__
    await route.handle(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 315, in handle
    await self.app(scope, receive, send)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
    await func(session)
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 264, in app
    solved_result = await solve_dependencies(
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 498, in solve_dependencies
    solved_result = await solve_dependencies(
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 498, in solve_dependencies
    solved_result = await solve_dependencies(
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 498, in solve_dependencies
    solved_result = await solve_dependencies(
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 523, in solve_dependencies
    solved = await solve_generator(
  File "/Users/test/Library/Caches/pypoetry/virtualenvs/fastapi-graphql-practice-1UuEp-7G-py3.10/lib/python3.10/site-packages/fastapi/dependencies/utils.py", line 443, in solve_generator
    cm = asynccontextmanager(call)(**sub_values)
  File "/Users/test/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 314, in helper
    return _AsyncGeneratorContextManager(func, args, kwds)
  File "/Users/test/.pyenv/versions/3.10.2/lib/python3.10/contextlib.py", line 103, in __init__
    self.gen = func(*args, **kwds)
TypeError: get_db_session() missing 1 required positional argument: 'request'
INFO:     connection open
INFO:     connection closed

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ljnsncommented, Jul 15, 2022

Until this is issue is solved, you can get rid of the error messages by changing the dependency slightly:

https://github.com/s3rius/FastAPI-template/blob/98f07cd0f9cc697ce5e64721c0a6505860729aba/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/dependencies.py#L7-L20

 async def get_db_session(request: Request = None) -> AsyncGenerator[AsyncSession, None]: 
     """ 
     Create and get database session. 
  
     :param request: current request. 
     :yield: database session. 
     """ 
     if request is None:
         yield None
         return

     session: AsyncSession = request.app.state.db_session_factory() 
  
     try:  # noqa: WPS501 
         yield session 
     finally: 
         await session.commit() 
         await session.close() 
1reaction
s3riuscommented, Jul 14, 2022

Hi there. I found no issues for this problem in strawberry-graphql repository. So I created one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - If request object is not being used should i remove it ...
If you were to remove 'req' as the first parameter, the request object would still be passed as the first parameter.
Read more >
Request() - Web APIs - MDN Web Docs
The Request() constructor creates a new Request object.
Read more >
Request & Response Objects - 4.x - CakePHP Cookbook
// Passed arguments $passedArgs = $this->request->getParam('pass');. Will all provide you access to the passed arguments. There are several important/useful ...
Read more >
Request Object | Branch CMS Documentation
The request object allows you to submit a POST or GET request to an URL. ... If this was a GET request then...
Read more >
Using the Request Directly - FastAPI
It would also mean that if you get data from the Request object directly (for ... being the Request FastAPI will know to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found