feat(serialization): add built-in SQLAlchemy DeclarativeBase serializer

SO
2d ago
+834-24

All Submissions:

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

PR Title

Add built-in serialization support for SQLAlchemy DeclarativeBase models

Description

This PR adds built-in serialization support for SQLAlchemy models inheriting from DeclarativeBase.

Previously, SQLAlchemy models required custom serializer registration to serialize loaded relationships safely. The new serializer includes loaded columns and relationships while omitting unloaded or expired attributes, preventing implicit lazy-loading errors such as DetachedInstanceError and MissingGreenlet.

The change preserves the existing SQLModel-specific serializer and adds regression tests and documentation explaining relationship serialization and eager loading.

Closes #7725