Skip to content

Support marshmallow 4 #758

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

Merged
merged 2 commits into from
Apr 25, 2025
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
5 changes: 3 additions & 2 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -45,12 +45,13 @@ docs = [
"alabaster==1.0.0",
]
tests = [
"packaging>=24.2",
"pytest==8.3.5",
"pytest-cov==6.1.1",
"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",
Expand Down
15 changes: 13 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.metadata
from collections import namedtuple

import pytest
Expand All @@ -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
Expand Down Expand Up @@ -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"""

Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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

Expand Down