Skip to content

Support marshmallow 4 and bcrypt 5; keep component names for Meta.exclude schemas - #45

Merged
zedrdave merged 5 commits into
mainfrom
chore/marshmallow4-deps-resolver-fix
Nov 20, 2026
Merged

zedrdave merged 5 commits into
mainfrom
chore/marshmallow4-deps-resolver-fix

Conversation

@zedrdave

Copy link
Copy Markdown
Member

Summary

  • Resolver fix: custom_schema_name_resolver inlined any schema with a non-empty exclude, including class-level Meta.exclude. It now inlines only instance-level modifiers (partial=, only=, exclude= beyond Meta.exclude), so Meta.exclude schemas get a named OpenAPI component.
  • Error handler fix: handle_generic_exception / handle_db_exception passed *e.args to one-arg exception classes and raised TypeError in debug mode for e.g. OSError(errno, strerror). Now str(e).
  • marshmallow 3 and 4: constraints widened to marshmallow>=3.20,<5, marshmallow-sqlalchemy>=1.4.2,<2; CI test matrix runs both majors; test @validates methods accept **kwargs.
  • bcrypt 5: passwords over 72 bytes are rejected with 422 at the schema boundary and check_password_hash returns False instead of raising.
  • Dependencies: lockfile refreshed (marshmallow 4.4, marshmallow-sqlalchemy 1.6, SQLAlchemy 2.1, bcrypt 5, flask-smorest 0.47); dev tooling bumped (pytest 9, ruff 0.17, Sphinx 9.0, myst-parser 5, ...). pyright fixes for marshmallow 4's generic Field.
  • Root-cause fix for the order-dependent test_user_polymorphic_subclass (lazy mapper configuration after the registry swap).

Verification

  • Full suite: 451 passed on marshmallow 4.4 and on marshmallow 3.26 / marshmallow-sqlalchemy 1.5.
  • OpenAPI spec dump identical across both marshmallow majors.
  • ruff, pyright and Sphinx 9 docs build clean.

Downstream notes

  • Generated clients may see a named type where Meta.exclude schemas were previously inlined.
  • Accounts whose password exceeded 72 bytes when hashed under bcrypt 4 can no longer log in and need a reset.
  • Projects moving to marshmallow 4 must add **kwargs to @validates / hook methods.

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread flask_more_smorest/utils.py Resolved
bcrypt 4 truncates silently, so a prefix match would have returned True.
@zedrdave
zedrdave merged commit b235341 into main Nov 20, 2026
13 checks passed
@zedrdave
zedrdave deleted the chore/marshmallow4-deps-resolver-fix branch November 20, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants