Skip to content

Commit 44cda8d

Browse files
authored
Merge pull request #758 from marshmallow-code/support_ma4
Support marshmallow 4
2 parents 1597d25 + 6be3c85 commit 44cda8d

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

.github/workflows/build-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
include:
15-
- { name: '3.9', python: '3.9', tox: py39 }
16-
- { name: '3.13', python: '3.13', tox: py313 }
15+
- { name: '3.9-ma3', python: '3.9', tox: py39-marshmallow3 }
16+
- { name: '3.9-ma4', python: '3.9', tox: py39-marshmallow4 }
17+
- { name: '3.13-ma4', python: '3.13', tox: py313-marshmallow4 }
1718
steps:
1819
- uses: actions/checkout@v4
1920
- uses: actions/setup-python@v5

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ requires-python = ">=3.9"
2626
dependencies = [
2727
"werkzeug>=3.0.1,<4",
2828
"flask>=3.0.2,<4",
29-
"marshmallow>=3.24.1,<4",
29+
"marshmallow>=3.24.1,<5",
3030
"webargs>=8.0.0,<9",
3131
"apispec[marshmallow]>=6.0.0,<7",
3232
]
@@ -45,12 +45,13 @@ docs = [
4545
"alabaster==1.0.0",
4646
]
4747
tests = [
48+
"packaging>=24.2",
4849
"pytest==8.3.5",
4950
"pytest-cov==6.1.1",
5051
"coverage==7.8.0",
5152
"werkzeug==3.1.3",
5253
"flask==3.1.0",
53-
"marshmallow==3.26.1",
54+
"marshmallow",
5455
"webargs==8.7.0",
5556
"apispec==6.8.1",
5657
"PyYAML==6.0.2",

tests/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.metadata
12
from collections import namedtuple
23

34
import pytest
@@ -6,8 +7,12 @@
67

78
import marshmallow as ma
89

10+
from packaging.version import Version
11+
912
from .mocks import DatabaseMock
1013

14+
MA_VERSION = Version(importlib.metadata.version("marshmallow"))
15+
1116

1217
class AppConfig:
1318
"""Base application configuration class
@@ -36,6 +41,12 @@ def app(request):
3641
return _app
3742

3843

44+
if MA_VERSION.major >= 4:
45+
pass_collection_true_kwargs = {"pass_collection": True}
46+
else:
47+
pass_collection_true_kwargs = {"pass_many": True}
48+
49+
3950
class CounterSchema(ma.Schema):
4051
"""Base Schema with load/dump counters"""
4152

@@ -50,12 +61,12 @@ def reset_load_count(cls):
5061
def reset_dump_count(cls):
5162
cls.dump_count = 0
5263

53-
@ma.post_load(pass_many=True)
64+
@ma.post_load(**pass_collection_true_kwargs)
5465
def increment_load_count(self, data, **kwargs):
5566
self.__class__.load_count += 1
5667
return data
5768

58-
@ma.post_dump(pass_many=True)
69+
@ma.post_dump(**pass_collection_true_kwargs)
5970
def increment_dump_count(self, data, **kwargs):
6071
self.__class__.dump_count += 1
6172
return data

tox.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
[tox]
2-
envlist = lint,py39,py310,py311,py312,py313
2+
envlist =
3+
lint
4+
{py39,py310,py311,py312,py313}-marshmallow4
5+
py39-marshmallow3
36
skip_missing_interpreters = True
47

58
[testenv]
69
extras = tests
10+
deps =
11+
marshmallow3: marshmallow>=3.26.1,<4
12+
marshmallow4: marshmallow>=4.0.0,<5
713
commands =
814
pytest --cov=flask_smorest --cov-branch --cov-report=term-missing --cov-report=xml
915

0 commit comments

Comments
 (0)