From cc91c2fa93a6a6a9049c99f14afcc5554d0a695b Mon Sep 17 00:00:00 2001 From: Wouter van Oorschot Date: Fri, 4 Nov 2022 19:51:54 +0100 Subject: [PATCH 1/8] Fix pre commit linting and testing Upgrade to black 22.3.0 to fix `ImportError: cannot import name '_unicodefun' from 'click'` Pin dependency on importlib-metadata to 4.12.0 to resolve `AttributeError: 'EntryPoints' object has no attribute 'get'` --- .pre-commit-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2adc914..34ffdfa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,21 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v2.11.0 + rev: v2.31.0 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black language_version: python3 - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.0 + rev: 3.9.2 hooks: - id: flake8 - additional_dependencies: [flake8-bugbear==21.4.3] + additional_dependencies: [flake8-bugbear==22.1.11, importlib-metadata==4.12.0] - repo: https://github.com/asottile/blacken-docs - rev: v1.10.0 + rev: v1.12.1 hooks: - id: blacken-docs - additional_dependencies: [black==20.8b1] + additional_dependencies: [black==22.3.0] From cb389e735d4bb0287969049078681294b99395ab Mon Sep 17 00:00:00 2001 From: woutervanoorschot Date: Wed, 9 Nov 2022 15:17:59 +0100 Subject: [PATCH 2/8] Remove deprecated BaseResponse from tests. Replace with Response from werkzeug.wrappers. See https://github.com/pallets/werkzeug/issues/1963 for details on deprecation. --- tests/test_core.py | 8 ++++---- tests/test_sqla.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 0dfebd9..f74d30e 100755 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,7 +1,7 @@ import json from flask import Flask, url_for -from werkzeug.wrappers import BaseResponse +from werkzeug.wrappers import Response from flask_marshmallow import Marshmallow from tests.markers import flask_1_req @@ -29,7 +29,7 @@ def test_schema(app, schemas, mockauthor): def test_jsonify_instance(app, schemas, mockauthor): s = schemas.AuthorSchema() resp = s.jsonify(mockauthor) - assert isinstance(resp, BaseResponse) + assert isinstance(resp, Response) assert resp.content_type == "application/json" obj = json.loads(resp.get_data(as_text=True)) assert isinstance(obj, dict) @@ -39,7 +39,7 @@ def test_jsonify_instance(app, schemas, mockauthor): def test_jsonify_collection(app, schemas, mockauthorlist): s = schemas.AuthorSchema() resp = s.jsonify(mockauthorlist, many=True) - assert isinstance(resp, BaseResponse) + assert isinstance(resp, Response) assert resp.content_type == "application/json" obj = json.loads(resp.get_data(as_text=True)) assert isinstance(obj, list) @@ -49,7 +49,7 @@ def test_jsonify_collection(app, schemas, mockauthorlist): def test_jsonify_collection_via_schema_attr(app, schemas, mockauthorlist): s = schemas.AuthorSchema(many=True) resp = s.jsonify(mockauthorlist) - assert isinstance(resp, BaseResponse) + assert isinstance(resp, Response) assert resp.content_type == "application/json" obj = json.loads(resp.get_data(as_text=True)) assert isinstance(obj, list) diff --git a/tests/test_sqla.py b/tests/test_sqla.py index 2bf138f..5f11e4e 100644 --- a/tests/test_sqla.py +++ b/tests/test_sqla.py @@ -1,7 +1,7 @@ import pytest from flask import Flask, url_for from flask_sqlalchemy import SQLAlchemy -from werkzeug.wrappers import BaseResponse +from werkzeug.wrappers import Response from flask_marshmallow import Marshmallow from flask_marshmallow.sqla import HyperlinkRelated @@ -130,7 +130,7 @@ class Meta: assert book_result["author_id"] == book.author_id resp = author_schema.jsonify(author) - assert isinstance(resp, BaseResponse) + assert isinstance(resp, Response) @requires_sqlalchemyschema def test_can_declare_sqla_auto_schemas(self, extma, models, db): @@ -168,7 +168,7 @@ class Meta: assert book_result["author_id"] == book.author_id resp = author_schema.jsonify(author) - assert isinstance(resp, BaseResponse) + assert isinstance(resp, Response) @requires_sqlalchemyschema def test_hyperlink_related_field(self, extma, models, db, extapp): From 910b62d026e99b5b635f2e955521c1f5e79c5db0 Mon Sep 17 00:00:00 2001 From: woutervanoorschot Date: Wed, 9 Nov 2022 15:20:31 +0100 Subject: [PATCH 3/8] Update to python 3.7 Bump pyupgrade version to python 3.7 Remove azure python 3.6 pipeline Require python >= 3.7 in setup --- .pre-commit-config.yaml | 2 +- azure-pipelines.yml | 1 - setup.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34ffdfa..103c30d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v2.31.0 hooks: - id: pyupgrade - args: [--py36-plus] + args: [--py37-plus] - repo: https://github.com/python/black rev: 22.3.0 hooks: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6412833..ee281bf 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,7 +27,6 @@ jobs: toxenvs: - lint - - py36-marshmallow3 - py37-marshmallow3 - py38-marshmallow3 - py39-marshmallow3 diff --git a/setup.py b/setup.py index 49c56dc..0bd3fe6 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ def read(fname): license="MIT", zip_safe=False, keywords="flask-marshmallow", - python_requires=">=3.6", + python_requires=">=3.7", classifiers=[ "Development Status :: 4 - Beta", "Environment :: Web Environment", From 859352ea4eea2933cf5b01830d0fe3c133399ade Mon Sep 17 00:00:00 2001 From: woutervanoorschot Date: Wed, 9 Nov 2022 15:38:57 +0100 Subject: [PATCH 4/8] Remove python 3.6 from tox Add python 3.10 to tox --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 24608a1..d91a53f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist= lint - py{36,37,38,39}-marshmallow3 + py{37,38,39,310}-marshmallow3 py39-lowest py39-marshmallowdev docs From d19d6b145445cfacabd75afa2672538250a964f8 Mon Sep 17 00:00:00 2001 From: woutervanoorschot Date: Wed, 9 Nov 2022 15:39:14 +0100 Subject: [PATCH 5/8] Try to update to spynx 4 to fix python 3.10 compatibility --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0bd3fe6..1cccb7e 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ "flask-sqlalchemy", "marshmallow-sqlalchemy>=0.24.0", ], - "docs": ["marshmallow-sqlalchemy>=0.13.0", "Sphinx==3.5.4", "sphinx-issues==1.2.0"], + "docs": ["marshmallow-sqlalchemy>=0.13.0", "Sphinx==4.5.0", "sphinx-issues==3.0.1"], "lint": [ "flake8==3.9.2", "flake8-bugbear==20.11.1", From 3a88e247796c47a8e0ff51ee18c8cb6160c54edd Mon Sep 17 00:00:00 2001 From: woutervanoorschot Date: Wed, 9 Nov 2022 15:49:15 +0100 Subject: [PATCH 6/8] Add python 3.10 pipeline --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ee281bf..b766d1c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,6 +30,7 @@ jobs: - py37-marshmallow3 - py38-marshmallow3 - py39-marshmallow3 + - py310-marshmallow3 - py39-lowest - py39-marshmallowdev From 339541e6d7ba39caa160613ab798b0145e940e0f Mon Sep 17 00:00:00 2001 From: Wouter van Oorschot Date: Fri, 4 Nov 2022 19:50:52 +0100 Subject: [PATCH 7/8] Require flask-sqlalchemy >= 3.0.0 The flask sqlalchemy extension is stored directly in the extensions dictionary in version 3.0.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1cccb7e..fd39157 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ EXTRAS_REQUIRE = { "sqlalchemy": [ - "flask-sqlalchemy", + "flask-sqlalchemy>=3.0.0", "marshmallow-sqlalchemy>=0.24.0", ], "docs": ["marshmallow-sqlalchemy>=0.13.0", "Sphinx==4.5.0", "sphinx-issues==3.0.1"], From 0997e9d735fb1288028df6e9de7b2cac05585ee1 Mon Sep 17 00:00:00 2001 From: Wouter van Oorschot Date: Fri, 4 Nov 2022 19:51:00 +0100 Subject: [PATCH 8/8] Get the db engine directly from the extensions dictionary. Resolves deprecation of the .db attribute in Flask-SQLAlchemy 3.0.0 --- src/flask_marshmallow/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flask_marshmallow/__init__.py b/src/flask_marshmallow/__init__.py index a0f0f1c..a3afa4d 100755 --- a/src/flask_marshmallow/__init__.py +++ b/src/flask_marshmallow/__init__.py @@ -111,7 +111,7 @@ def init_app(self, app): # If using Flask-SQLAlchemy, attach db.session to SQLAlchemySchema if has_sqla and "sqlalchemy" in app.extensions: - db = app.extensions["sqlalchemy"].db + db = app.extensions["sqlalchemy"] if self.SQLAlchemySchema: self.SQLAlchemySchema.OPTIONS_CLASS.session = db.session if self.SQLAlchemyAutoSchema: