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

Ensure ASGI State is added to all subsequent ASGI requests #240

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

ashleysommer
Copy link

@ashleysommer ashleysommer commented Aug 22, 2024

The ASGIMiddleware class has a state (Dict) property.
State can be written to if the ASGI Lifespan startup handler writes to it, but it is never used for anything after that.

The ASGI Spec states that contents of the lifespan startup's 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.

This PR implements that final missing link, adds a shallow copy of the state dict to every subsequent ASGI Request, as specified in the ASGI spec.

Fixes Azure/azure-functions-python-worker#1566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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