Skip to content

Commit

Permalink
Remove references to deprecated _app_ctx_stack and _request_ctx_stack…
Browse files Browse the repository at this point in the history
… of flask
  • Loading branch information
rubencho authored and marksteward committed Jul 24, 2023
1 parent 3c41db2 commit a7a6bd7
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions sqlalchemy_continuum/plugins/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,27 @@
flask = None
try:
import flask
from flask import request
from flask.globals import _app_ctx_stack, _request_ctx_stack
from flask import current_app, has_app_context, has_request_context, request
except ImportError:
pass
from sqlalchemy_utils import ImproperlyConfigured

from .base import Plugin


def fetch_current_user_id():
from flask_login import current_user
if has_request_context():
from flask_login import current_user

# Return None if we are outside of request context.
if _app_ctx_stack.top is None or _request_ctx_stack.top is None:
return
try:
return current_user.id
except AttributeError:
return
try:
return current_user.id
except AttributeError:
return


def fetch_remote_addr():
# Return None if we are outside of request context.
if _app_ctx_stack.top is None or _request_ctx_stack.top is None:
return
return request.remote_addr
if has_app_context() and has_request_context():
return request.remote_addr


class FlaskPlugin(Plugin):
Expand Down

0 comments on commit a7a6bd7

Please sign in to comment.