Skip to content

docs: restore SerializationPlugin implementation example#4711

Merged
cofin merged 2 commits into
litestar-org:mainfrom
akerem16:docs/serialization-plugin-example
Apr 25, 2026
Merged

docs: restore SerializationPlugin implementation example#4711
cofin merged 2 commits into
litestar-org:mainfrom
akerem16:docs/serialization-plugin-example

Conversation

@akerem16

@akerem16 akerem16 commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3778.

The SerializationPlugin section of docs/usage/plugins/index.rst currently describes the caching pattern used by a serialization plugin ("check the _type_dto_map dictionary, add it to the dictionary, return it") but does not actually show any code. The original literalinclude directive pointed at litestar/contrib/sqlalchemy/plugins/serialization.py, which was removed when the SQLAlchemy plugin moved to advanced-alchemy (08297fd), leaving the prose orphaned.

Changes

  • Add a new standalone example docs/examples/plugins/serialization_plugin_protocol.py that implements SerializationPlugin for a Company dataclass. It mirrors the exact caching pattern used by advanced-alchemy's SQLAlchemySerializationPlugin (unwrap collection annotations, check a _type_dto_map cache, parametrise DataclassDTO on first encounter).
  • Update docs/usage/plugins/index.rst SerializationPluginExample to literalinclude the new example and describe its behaviour in terms of the concrete implementation shown. Keep a pointer to advanced-alchemy for production SQLAlchemy usage.

The example is standalone and doesn't require any external dependencies; ruff check / ruff format pass locally.

Test plan

  • Sphinx build renders the updated page
  • literalinclude directive resolves (example path exists)
  • python docs/examples/plugins/serialization_plugin_protocol.py imports cleanly

📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4711

@akerem16
akerem16 requested review from a team as code owners April 20, 2026 11:55
@github-actions github-actions Bot added area/docs This PR involves changes to the documentation size: small type/docs pr/external Triage Required 🏥 This requires triage labels Apr 20, 2026
The SerializationPlugin section in `docs/usage/plugins/index.rst` described
the caching pattern used by a plugin implementation but no longer pointed at
any code. The original `literalinclude` referenced
`litestar/contrib/sqlalchemy/plugins/serialization.py`, which was removed when
SQLAlchemy plugins moved to advanced-alchemy, leaving the prose orphaned.

Add a minimal standalone example `docs/examples/plugins/serialization_plugin_protocol.py`
that mirrors advanced-alchemy's `SQLAlchemySerializationPlugin` pattern using
a dataclass-backed model and `DataclassDTO`, and rewire the docs section to
include it and summarise its behaviour. Point readers at the advanced-alchemy
library docs for a production-grade SQLAlchemy implementation.

Fixes litestar-org#3778
Sphinx docs build fails with nitpicky mode:

  docs/usage/plugins/index.rst:85: WARNING: py:class reference target
  not found: litestar.dto.DataclassDTO [ref.class]

The class is documented from its defining module
(litestar.dto.dataclass_dto) via automodule, which is the path Sphinx
resolves. Other prose in docs/usage/dto and docs/tutorials uses the
same full path for the same reason.
@cofin
cofin force-pushed the docs/serialization-plugin-example branch from e9175f2 to 88ad272 Compare April 25, 2026 21:08
@cofin
cofin merged commit a926a2b into litestar-org:main Apr 25, 2026
25 checks passed
@akerem16
akerem16 deleted the docs/serialization-plugin-example branch April 25, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs This PR involves changes to the documentation pr/external pr/internal size: small Triage Required 🏥 This requires triage type/docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: SerializationPluginProtocol example is cut off

2 participants