Skip to content

fix: Inlcude FKs when creating marshmallow-sqlalchemy schemas#2443

Open
mschmo wants to merge 4 commits into
dpgaspar:masterfrom
mschmo:fix-marshmallow-schema-fk-key-error
Open

fix: Inlcude FKs when creating marshmallow-sqlalchemy schemas#2443
mschmo wants to merge 4 commits into
dpgaspar:masterfrom
mschmo:fix-marshmallow-schema-fk-key-error

Conversation

@mschmo
Copy link
Copy Markdown
Contributor

@mschmo mschmo commented Mar 19, 2026

Fixes #2361 and #2425

In marshmallow-sqlalchemy 1.x, the SQLAlchemyAutoSchema class defaults include_fk to False. When FAB generates the schemas for security models like PermissionView, it explicitly requests foreign key columns (like permission_id and view_menu_id). However, because include_fk is False, the SQLAlchemyAutoSchemaMeta metaclass filters these fields out before the schema is initialized. Marshmallow 4 then throws a KeyError (due to this change) because it expects all fields listed in Meta.fields to be present in the schema.

In order to preserve existing API behavior, include_fk is set to False when generating nested schemas for relationship fields.

@mschmo

This comment was marked as resolved.

mschmo added 2 commits March 19, 2026 22:51
Defaults to true for top-level schemas, and set as false for nested schemas.
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.

KeyError: permission_id-the version of marshmallow

1 participant