feat: add flag to run functions framework in asgi stack#376
Merged
maemayve merged 22 commits intoGoogleCloudPlatform:mainfrom Jun 12, 2025
Merged
feat: add flag to run functions framework in asgi stack#376maemayve merged 22 commits intoGoogleCloudPlatform:mainfrom
maemayve merged 22 commits intoGoogleCloudPlatform:mainfrom
Conversation
- Add uvicorn and uvicorn-worker to async optional dependencies - Refactor gunicorn.py with BaseGunicornApplication for shared config - Add UvicornApplication class for ASGI apps - Add StarletteApplication in asgi.py for development mode - Update HTTPServer to auto-detect Flask (WSGI) vs other (ASGI) apps - Add --gateway CLI flag to choose between wsgi and asgi - Update test_http.py to use Flask instance in tests
- Add tests for HTTPServer ASGI/WSGI auto-detection - Add tests for StarletteApplication and UvicornApplication - Add tests for CLI --gateway flag functionality - Add integration tests for async functions with ASGI - Ensure 100% code coverage for new ASGI features - Apply black and isort formatting to test files
ASGI mode does not support automatic conversion from legacy events to CloudEvents, so validateMapping must be false for CloudEvent conformance tests.
Create a copy of the options dict before modifying it to prevent side effects when the same options dict is reused elsewhere. This could cause issues with timeout tests.
…ling - Add pragma: no cover comments for ASGI-specific code paths that won't execute in Python 3.7 - Fix options dict handling to use consistent variable names to avoid confusion
…asses Remove the BaseGunicornApplication abstraction as it was causing issues with the timeout mechanism. Each class now independently extends gunicorn.app.base.BaseApplication, which is cleaner and avoids the problems we were seeing with shared state and options handling.
Remove unnecessary changes to GunicornApplication class, keeping only the UvicornApplication addition for ASGI support.
maemayve
approved these changes
Jun 12, 2025
Contributor
maemayve
left a comment
There was a problem hiding this comment.
Thanks so much for this contribution. I appreciate the parameterized tests.
| # limitations under the License. | ||
|
|
||
| from flask import Flask | ||
|
|
Contributor
There was a problem hiding this comment.
can you remove whitespace?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a new flag to enable ASGI support to the Functions Framework for Python allowing users to run asynchronous functions.
Key changes:
--gatewayflag. The available options arewsgi(default) andasgi.Note: This PR does not include support for execution ID and Jinja2 templates for ASGI applications. This will be addressed in a subsequent PR.