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

Use Flask request_ctx instead of _request_ctx_stack #1583

Merged
merged 2 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connexion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
Api = FlaskApi

# This version is replaced during release process.
__version__ = "2020.0.dev1"
__version__ = "3.0.dev0"
4 changes: 2 additions & 2 deletions connexion/apis/flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_request(cls, *args, **params):
flask_request = flask.request
scope = flask_request.environ["asgi.scope"]
context_dict = scope.get("extensions", {}).get("connexion_context", {})
setattr(flask._request_ctx_stack.top, "connexion_context", context_dict)
setattr(flask.globals.request_ctx, "connexion_context", context_dict)
request = ConnexionRequest(
flask_request.url,
flask_request.method,
Expand Down Expand Up @@ -198,7 +198,7 @@ def _set_jsonifier(cls):


def _get_context():
return getattr(flask._request_ctx_stack.top, "connexion_context")
return getattr(flask.globals.request_ctx, "connexion_context")


context = LocalProxy(_get_context)
5 changes: 5 additions & 0 deletions connexion/jsonifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def wrapped_default(self, o):
class JSONEncoder(json.JSONEncoder):
"""The default Connexion JSON encoder. Handles extra types compared to the
built-in :class:`json.JSONEncoder`.

- :class:`datetime.datetime` and :class:`datetime.date` are
serialized to :rfc:`822` strings. This is the same as the HTTP
date format.
- :class:`uuid.UUID` is serialized to a string.
"""

@wrap_default
Expand Down
2 changes: 2 additions & 0 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class TestMiddleware:
"""Middleware to check if operation is accessible on scope."""

__test__ = False
nielsbox marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, app):
self.app = app

Expand Down