miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.36k stars 890 forks source link

flask._request_ctx_stack deprecated #1856

Closed woutdenolf closed 2 years ago

woutdenolf commented 2 years ago
  /usr/local/lib/python3.7/site-packages/flask_socketio/__init__.py:19: DeprecationWarning: '_request_ctx_stack' is deprecated and will be removed in Flask 2.3.
    from flask import _request_ctx_stack, has_request_context, json as flask_json

From the Flask changelog:

The app and request contexts are managed using Python context
vars directly rather than Werkzeug’s LocalStack. This should result
in better performance and memory use. [#4682](https://github.com/pallets/flask/pull/4682)

    Extension maintainers, be aware that _app_ctx_stack.top and _request_ctx_stack.top
    are deprecated. Store data on g instead using a unique prefix, like g._extension_name_attr.
mokadevcloud commented 2 years ago

Hi, I have a similar warning after upgrading to Flask 2.2.1. Posting it here as the warning is slightly different:

/home/project/env/lib/python3.8/site-packages/flask_socketio/__init__.py:754: DeprecationWarning: '_request_ctx_stack' is deprecated and will be removed in Flask 2.3. Use 'g' to store data, or 'request_ctx' to access the current context.
  _request_ctx_stack.top.session = session_obj

Thanks

miguelgrinberg commented 2 years ago

Please give the main branch a try for a fix. The code adapts to work both in >= 2.2 and < 2.2 releases.

woutdenolf commented 2 years ago

Seems to work fine. Thanks!