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

Merge app and request contexts into a single context (#5639) #5705

Closed
wants to merge 2 commits into from

Conversation

ascender1729
Copy link

Merge app and request contexts into a single context (#5639)

This PR implements the proposal from #5639 to merge the app and request contexts into a single execution context. This simplifies the implementation by:

  1. Creating a new ExecutionContext class that combines both app and request contexts
  2. Using a single context variable _cv_execution instead of separate _cv_app and _cv_request
  3. Maintaining backward compatibility by setting both old context vars when needed
  4. Adding deprecation warnings for the old context methods
  5. Updating all globals to use the new execution context

Key changes:

  • Added new ExecutionContext class in ctx.py that handles both app and request contexts
  • Updated globals.py to use the new execution context for all proxies
  • Modified app.py to create execution contexts instead of separate app/request contexts
  • Added deprecation warnings for has_app_context() and has_request_context()
  • Simplified context management by removing the need to track multiple context stacks

The changes maintain backward compatibility while paving the way for a cleaner implementation in Flask 4.0. The new execution context:

  • Has a single context variable instead of two
  • Handles both app and request state in one place
  • Maintains the same behavior for existing code
  • Provides clearer error messages when contexts are missing

This change will make the codebase simpler and easier to understand, while also making it more efficient by reducing the number of context variables that need to be managed.

Closes #5639

@davidism
Copy link
Member

Sorry if this was unclear, but the issue was assigned to me because I did no want others working on it. It's extremely complex and will require a lot of thought on compatibility and deprecation. At a glance, this PR has numerous issues, and it's not something I want to shepherd through review. It also seems like it was written at least in part by LLM tools, contributing to the quality issues.

@davidism davidism closed this Mar 30, 2025
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.

merge app and request contexts into a single context
2 participants