Repository navigation
Support marshmallow 4 and bcrypt 5; keep component names for Meta.exclude schemas - #45
Merged
Merged
Conversation
…handler The spec name resolver inlined any schema with a non-empty exclude set, including class-level Meta.exclude. It now inlines only instance-level modifiers (partial=, only=, exclude= beyond Meta.exclude). handle_generic_exception and handle_db_exception passed *e.args to exception classes that take one positional argument, raising TypeError in debug mode for multi-arg exceptions such as OSError(errno, strerror).
- @validates methods in tests accept **kwargs (marshmallow 4 passes data_key) - CI test matrix runs marshmallow 3 and 4 - passwords longer than 72 bytes are rejected with 422 at the schema boundary and check_password_hash returns False instead of raising (bcrypt 5 raises instead of silently truncating)
Runtime: marshmallow 4.4, marshmallow-sqlalchemy 1.6, SQLAlchemy 2.1, bcrypt 5, flask-smorest 0.47. Dev: pytest 9, pytest-cov 7, pre-commit 4, ruff 0.17, Sphinx 9.0, myst-parser 5, sphinx-rtd-theme 3, sphinx-autodoc-typehints 3.6 (newest lines installable on Python 3.11). pyright with marshmallow 4 made Field generic and flagged Iterator on @contextmanager; typed accordingly and dropped two stale suppressions. test_user_polymorphic_subclass failed when run in isolation (or first under xdist): the default models' relationships were configured lazily after init_fms had been re-pointed at the custom models, so User.roles resolved against CustomUserRole. The test now configures mappers first.
…ow 3 marshmallow 3's Field is not generic; the annotation was evaluated at import time on Python < 3.14 and raised TypeError.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The password helper can accept overlong inputs under supported bcrypt 4 because checkpw truncates them to 72 bytes; it needs an encoded-length check and a regression test using a matching 72-byte prefix.
1 open issue
What changed in this PR
This PR adds marshmallow 4 and bcrypt 5 support to Flask-More-Smorest while preserving named OpenAPI components for schemas with class-level Meta.exclude.
Changes:
- Distinguishes class-level exclusions from instance filtering in schema naming.
- Adds password-length validation and fixes error handling for exceptions with multiple arguments.
- Updates dependencies, compatibility annotations, regression tests, and CI coverage for both marshmallow majors.
| File | Description |
|---|---|
tests/unit/test_utils.py |
Tests password byte limits and long-password verification. |
tests/unit/test_user_blueprint.py |
Tests rejection of overlong login passwords. |
tests/unit/test_polymorphic_inheritance.py |
Configures mappers before swapping model registries. |
tests/unit/test_exceptions.py |
Tests handling of multi-argument exceptions. |
tests/integration/test_user_demoapp_integration.py |
Tests component naming for class-level and instance exclusions. |
tests/integration/test_arg_schema.py |
Makes validators compatible with marshmallow 4 keyword arguments. |
pyproject.toml |
Widens runtime compatibility and updates development dependencies. |
flask_more_smorest/utils.py |
Adds password-length validation and catches bcrypt verification errors. |
flask_more_smorest/sqla/base_model.py |
Updates the context-manager return annotation. |
flask_more_smorest/perms/user_schemas.py |
Applies password-length validation to password fields. |
flask_more_smorest/perms/base_perms_model.py |
Updates the permission context-manager return annotation. |
flask_more_smorest/perms/api.py |
Preserves component names for Meta.exclude schemas. |
flask_more_smorest/error/error_handlers.py |
Uses exception strings instead of unpacking arguments. |
flask_more_smorest/crud/query_filtering.py |
Adds deferred, generic field annotations for compatibility. |
flask_more_smorest/crud/blueprint_operationid.py |
Removes obsolete pyright suppression comments. |
docs/requirements.txt |
Updates documentation dependencies. |
CHANGELOG.md |
Documents compatibility changes, fixes, and migration implications. |
.github/workflows/ci-cd.yml |
Adds a marshmallow-major test matrix and separate cache keys. |
Review effort: Balanced
bcrypt 4 truncates silently, so a prefix match would have returned True.
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
custom_schema_name_resolverinlined any schema with a non-emptyexclude, including class-levelMeta.exclude. It now inlines only instance-level modifiers (partial=,only=,exclude=beyondMeta.exclude), soMeta.excludeschemas get a named OpenAPI component.handle_generic_exception/handle_db_exceptionpassed*e.argsto one-arg exception classes and raisedTypeErrorin debug mode for e.g.OSError(errno, strerror). Nowstr(e).marshmallow>=3.20,<5,marshmallow-sqlalchemy>=1.4.2,<2; CI test matrix runs both majors; test@validatesmethods accept**kwargs.check_password_hashreturnsFalseinstead of raising.Field.test_user_polymorphic_subclass(lazy mapper configuration after the registry swap).Verification
Downstream notes
Meta.excludeschemas were previously inlined.**kwargsto@validates/ hook methods.