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

Fix #79: add support for recent versions of Flask #103

Merged
merged 4 commits into from
Mar 18, 2024
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
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
---------


2024.3.1 (unreleased)
~~~~~~~~~~~~~~~~~~~~~

- Add support for Flask 2.3 and 3.0 (#103)


2024.3.0
~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions src/dockerflow/checks/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This is a minor port of the Django checks system messages to be used
for Dockerflow checks of the Flask and Sanic extensions.
"""

# Levels
DEBUG = 10
INFO = 20
Expand Down
1 change: 1 addition & 0 deletions src/dockerflow/django/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def heartbeat_passed_handler(sender, level, **kwargs):
def heartbeat_failed_handler(sender, level, **kwargs):
statsd.incr('heartbeat.fail')
"""

from django.dispatch import Signal

heartbeat_passed = Signal()
Expand Down
1 change: 1 addition & 0 deletions src/dockerflow/flask/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
This module contains a few built-in checks for the Flask integration.
"""

from sqlalchemy import text

from ... import health
Expand Down
1 change: 1 addition & 0 deletions src/dockerflow/flask/checks/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This exposes dockerflow.checks.messages as dockerflow.flask.checks.messages
for backwards compatibility
"""

import warnings

from ...checks.messages import * # noqa
Expand Down
1 change: 1 addition & 0 deletions src/dockerflow/flask/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def heartbeat_failed_handler(sender, level, **extra):
statsd.incr('heartbeat.fail')

"""

from flask.signals import Namespace

dockerflow_signals = Namespace()
Expand Down
1 change: 1 addition & 0 deletions src/dockerflow/sanic/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
This module contains built-in checks for the Sanic integration.
"""

from .. import health
from ..checks import ( # noqa
CRITICAL,
Expand Down
3 changes: 3 additions & 0 deletions tests/constraints/flask-2.3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask>=2.3,<3
Flask-SQLAlchemy<4
Werkzeug<4
3 changes: 3 additions & 0 deletions tests/constraints/flask-3.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask>=3,<4
Flask-SQLAlchemy<4
Werkzeug>=3,<4
12 changes: 9 additions & 3 deletions tests/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from flask_login.mixins import UserMixin
from flask_migrate import Migrate
from flask_redis import FlaskRedis
from flask_sqlalchemy import SQLAlchemy, get_debug_queries
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import DBAPIError, SQLAlchemyError

from dockerflow import checks, health
Expand All @@ -24,6 +24,12 @@
check_redis_connected,
)

try:
from flask_sqlalchemy.record_queries import get_recorded_queries
except ImportError:
# flask-sqlalchemy < 3
from flask_sqlalchemy import get_debug_queries as get_recorded_queries


class MockUser(UserMixin):
def __init__(self, id):
Expand Down Expand Up @@ -186,10 +192,10 @@ def warning_check():

def test_lbheartbeat_makes_no_db_queries(dockerflow, app):
with app.app_context():
assert len(get_debug_queries()) == 0
assert len(get_recorded_queries()) == 0
response = app.test_client().get("/__lbheartbeat__")
assert response.status_code == 200
assert len(get_debug_queries()) == 0
assert len(get_recorded_queries()) == 0


def test_full_redis_check(mocker):
Expand Down
8 changes: 5 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ envlist =
py{38,39,310,311}-dj{40,41,42}
py{310,311,312}-dj{50}
py{38,39,310,311,312}-fa100
py{38,39,310,311}-fl{20,21,22}
py{38,39,310,311}-fl{20,21,22,23,30}
py{38,39,310,311}-s{21,22}

[testenv]
Expand All @@ -21,7 +21,7 @@ deps =
-rtests/requirements/default.txt
dj{32,40,41,42,50}: -rtests/requirements/django.txt
fa100: -rtests/requirements/fastapi.txt
fl{20,21,22}: -rtests/requirements/flask.txt
fl{20,21,22,23,30}: -rtests/requirements/flask.txt
s{21,22}: -rtests/requirements/sanic.txt
dj32: -ctests/constraints/django-3.2.txt
dj40: -ctests/constraints/django-4.0.txt
Expand All @@ -32,13 +32,15 @@ deps =
fl20: -ctests/constraints/flask-2.0.txt
fl21: -ctests/constraints/flask-2.1.txt
fl22: -ctests/constraints/flask-2.2.txt
fl23: -ctests/constraints/flask-2.3.txt
fl30: -ctests/constraints/flask-3.0.txt
s21: -ctests/constraints/sanic-21.txt
s22: -ctests/constraints/sanic-22.txt
commands =
python --version
dj{32,40,41,42,50}: pytest --no-migrations -o DJANGO_SETTINGS_MODULE=tests.django.settings -o django_find_project=false {posargs:tests/core/ tests/django}
fa{100}: pytest {posargs: tests/core/ tests/fastapi/}
fl{20,21,22}: pytest {posargs:tests/core/ tests/flask/}
fl{20,21,22,23,30}: pytest {posargs:tests/core/ tests/flask/}
s{21,22}: pytest {posargs:tests/core/ tests/sanic/}

[testenv:py311-docs]
Expand Down
Loading