Skip to content

Commit

Permalink
Use Flask request_ctx instead of _request_ctx_stack (#1583)
Browse files Browse the repository at this point in the history
* Use Flask request_ctx instead of _request_ctx_stack

* Suppress first party warnings
  • Loading branch information
RobbeSneyders committed Sep 7, 2022
1 parent 45468a1 commit 3e52c78
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
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

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

Expand Down

0 comments on commit 3e52c78

Please sign in to comment.