From dc4717dbe55c8e9820f7aecf426bc3483fdc1c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Tue, 4 Mar 2025 00:14:12 +0100 Subject: [PATCH 1/2] Support marshmallow 4 --- pyproject.toml | 1 + tests/conftest.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 03e3d36e..fdea2e7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ docs = [ "alabaster==1.0.0", ] tests = [ + "packaging>=24.2", "pytest==8.3.5", "pytest-cov==6.1.1", "coverage==7.8.0", diff --git a/tests/conftest.py b/tests/conftest.py index 6845129f..584fba18 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import importlib.metadata from collections import namedtuple import pytest @@ -6,8 +7,12 @@ import marshmallow as ma +from packaging.version import Version + from .mocks import DatabaseMock +MA_VERSION = Version(importlib.metadata.version("marshmallow")) + class AppConfig: """Base application configuration class @@ -36,6 +41,12 @@ def app(request): return _app +if MA_VERSION.major >= 4: + pass_collection_true_kwargs = {"pass_collection": True} +else: + pass_collection_true_kwargs = {"pass_many": True} + + class CounterSchema(ma.Schema): """Base Schema with load/dump counters""" @@ -50,12 +61,12 @@ def reset_load_count(cls): def reset_dump_count(cls): cls.dump_count = 0 - @ma.post_load(pass_many=True) + @ma.post_load(**pass_collection_true_kwargs) def increment_load_count(self, data, **kwargs): self.__class__.load_count += 1 return data - @ma.post_dump(pass_many=True) + @ma.post_dump(**pass_collection_true_kwargs) def increment_dump_count(self, data, **kwargs): self.__class__.dump_count += 1 return data From 6be3c85eb8f081da8f01b20f32b67d4245693b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lafr=C3=A9choux?= Date: Fri, 18 Apr 2025 22:32:00 +0200 Subject: [PATCH 2/2] Test on both marshmallow 3 and 4 --- .github/workflows/build-release.yml | 5 +++-- pyproject.toml | 4 ++-- tox.ini | 8 +++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index f60e6054..22284a76 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -12,8 +12,9 @@ jobs: fail-fast: false matrix: include: - - { name: '3.9', python: '3.9', tox: py39 } - - { name: '3.13', python: '3.13', tox: py313 } + - { name: '3.9-ma3', python: '3.9', tox: py39-marshmallow3 } + - { name: '3.9-ma4', python: '3.9', tox: py39-marshmallow4 } + - { name: '3.13-ma4', python: '3.13', tox: py313-marshmallow4 } steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/pyproject.toml b/pyproject.toml index fdea2e7d..a8034e26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ requires-python = ">=3.9" dependencies = [ "werkzeug>=3.0.1,<4", "flask>=3.0.2,<4", - "marshmallow>=3.24.1,<4", + "marshmallow>=3.24.1,<5", "webargs>=8.0.0,<9", "apispec[marshmallow]>=6.0.0,<7", ] @@ -51,7 +51,7 @@ tests = [ "coverage==7.8.0", "werkzeug==3.1.3", "flask==3.1.0", - "marshmallow==3.26.1", + "marshmallow", "webargs==8.7.0", "apispec==6.8.1", "PyYAML==6.0.2", diff --git a/tox.ini b/tox.ini index 249e329a..cc684860 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,15 @@ [tox] -envlist = lint,py39,py310,py311,py312,py313 +envlist = + lint + {py39,py310,py311,py312,py313}-marshmallow4 + py39-marshmallow3 skip_missing_interpreters = True [testenv] extras = tests +deps = + marshmallow3: marshmallow>=3.26.1,<4 + marshmallow4: marshmallow>=4.0.0,<5 commands = pytest --cov=flask_smorest --cov-branch --cov-report=term-missing --cov-report=xml