Add marshmallow 4.x support with backward compatibility#326
Merged
gtmanfred merged 11 commits intoplangrid:masterfrom Feb 2, 2026
Merged
Add marshmallow 4.x support with backward compatibility#326gtmanfred merged 11 commits intoplangrid:masterfrom
gtmanfred merged 11 commits intoplangrid:masterfrom
Conversation
- Add MARSHMALLOW_VERSION_MAJOR constant for version detection - Add is_schema_ordered() helper to handle removed 'ordered' attribute - Update get_schema_fields() and get_required() to use is_schema_ordered() - Bump marshmallow version constraint from <4 to <5 In marshmallow 4.x, the 'ordered' Meta option was removed because field order is now always preserved (Python 3.7+ dict ordering). The is_schema_ordered() helper abstracts this difference: - 3.x: checks schema.ordered attribute (default False = sort fields) - 4.x: always returns True (fields preserve insertion order)
marshmallow-objects is an archived library incompatible with marshmallow 4.x (passes 'context' to Schema.__init__() which was removed). - Import marshmallow_objects conditionally with try/except - Test instantiation to detect runtime incompatibility - Define MARSHMALLOW_OBJECTS_AVAILABLE flag - Move Model class definitions inside conditional block - Create conditional test case lists for parametrized tests Users on marshmallow 3.x can still use marshmallow-objects.
- Remove 'parametrize' import causing source reading issues - Split test_additional_properties into 4 individual tests - Add skipif for test_self_referential_nested_pre_3_3 (uses removed 'self' nested reference in 4.x) - Compare 'required' field as set since order varies between versions - Add MARSHMALLOW_VERSION constant for version-specific behavior
Error message format for datetime validation changed between versions. Check for 'isoformat' substring rather than exact message match.
Test against: - marshmallow==4.0.0 - marshmallow==4.0.1 - marshmallow>4.0.1 (latest)
c1dfbdf to
21206a6
Compare
Closed
Contributor
|
Howdy, thanks for opening this. I will try and get a review in before the end of the week. |
gtmanfred
reviewed
Jan 26, 2026
To avoid pip install marshmallow>4 piping the output of `pip install marshmallow` to a file called `4`.
illusional
reviewed
Feb 2, 2026
Co-authored-by: Michael Franklin <michael@illusional.net>
…ar into mashmallow_4x_support
illusional
approved these changes
Feb 2, 2026
gtmanfred
approved these changes
Feb 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for marshmallow 4.x while maintaining backward compatibility with marshmallow 3.x.
Changes
Core Library
Test Fixes
CI
Testing
Breaking Changes in Marshmallow 4.x Addressed