Closed BakinSergey closed 2 years ago
I think this is a case of out-of-date documentation as your workaround appears to be the intended functionality.
Looking at this and this, it seems impossible to achieve the functionality as described in the documentation since info.context["response"]
has no attribute background
. Instead, info.context
has background_tasks
as a field (if a dictionary) or an attribute (if inheriting from BaseContext
).
I will amend the documentation to better describe this situation and so hopefully resolve this issue :D
it seems like it has, but not work(not handle), but in other case(for ex FileResponse) it works
i check - this(2) will work, but (1) in case of context['response'].background - will not
Ahh okay, interesting. I see what you're driving at! You may be mixing up the different Strawberry integrations.
You initially linked here, which actually applies to the Strawberry-ASGI integration and not the Strawberry-FastAPI integration. If you go here then you will see the correct FastAPI functionality that allows for adding background tasks to the context object, which is the functionality you desire.
Since these are different integrations, it's important that you use the correct functionality for the integration that you choose. You chose FastAPI, so you should follow these docs.
u right! i was only google by "Setting background tasks" ))) Thx for your time!
Great! :D If you feel that this is resolved could you please close the issue, thanks!
the problem is that no background task is called in the described here way(see comments in code)
Ubuntu 20.04 python = "~3.8" strawberry-graphql = {extras = ["fastapi"], version = "^0.108.0"} fastapi = "^0.75.2"