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

[Bug] ASGIFunctionApp - scope.state from lifespan startup is not delivered in subsequent request.state #1566

Open
ashleysommer opened this issue Aug 22, 2024 · 1 comment · May be fixed by Azure/azure-functions-python-library#240
Assignees

Comments

@ashleysommer
Copy link

ashleysommer commented Aug 22, 2024

Expected Behavior

The ASGI Spec states that contents of the lifespan startup's scope.state dict is stored by the ASGI server, and the state is added to any subsequent ASGI Requests.
https://asgi.readthedocs.io/en/latest/specs/lifespan.html

Applications often want to persist data from the lifespan cycle to request/response handling. ... The server will ensure that a shallow copy of the namespace is passed into each subsequent request/response call into the application.

Actual Behavior

When a lifespan startup handler adds content to the scope.state dict, it is correctly stored in the ASGIMiddleware state property, however the state is never used again, it is not added to request.state in subsequent ASGI Requests as expected.

Steps to Reproduce

  1. Create an ASGI App that supports ASGI Lifetime handling (eg, Starlette, or FastAPI)
  2. Create a Lifetime handler, that receives the Scope object
  3. Add some content to the Scope.state dict,
  • eg, scope.state["message"] = "hello world"
  1. Add a ASGI request handler that receives a request parameter.
  2. Attempt to read request.state["message"] from the request
  • result = request.state == {} - Empty dict
  • error index error, "message" not in request.state

Where are you facing this problem?

Local - Core Tools

@ashleysommer
Copy link
Author

I've created a PR to fix this now, on the azure-functions repo: Azure/azure-functions-python-library#240

@YunchuWang YunchuWang self-assigned this Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants