Skip to content

Add column_fields option to Related for non-standard column types - #755

Closed
harmehak0173 wants to merge 1 commit into
marshmallow-code:devfrom
harmehak0173:feat/issue-478-related-column-field
Closed

harmehak0173 wants to merge 1 commit into
marshmallow-code:devfrom
harmehak0173:feat/issue-478-related-column-field

Conversation

@harmehak0173

Copy link
Copy Markdown

Fixes #478

Summary

Related previously read and passed raw column attribute values directly, causing JSON serialization failures (e.g., for SQLAlchemy Enum columns) and preventing field-level deserialization/validation for custom column types.

Changes

  • Add a keyword-only column_fields parameter to Related accepting either a marshmallow Field instance/class (for single-column relationships) or a mapping of column names to Field instances/classes (for single- or multi-column relationships).
  • Apply configured column_fields in Related._serialize (preserving None values) and Related._deserialize (without mutating the caller's input dictionary, and propagating ValidationError cleanly).
  • Validate column_fields types, unknown column names, and single-field usage with multi-column Related.
  • Add unit tests in tests/test_sqlalchemy_schema.py covering fields.Enum, custom Field classes, multi-column mappings, None values, JSON dumps(), and validation error paths.

Testing

  • pytest (111 passed)
  • mypy (0 errors)
  • ruff check & ruff format --check (all checks passed)

@sloria

sloria commented Nov 29, 2026

Copy link
Copy Markdown
Member

please see our AI policy

@sloria sloria closed this Nov 29, 2026
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.

Using Related(column=...) with non-standard column types

2 participants