feat: deprecate litestar.repository in favor of advanced_alchemy#4758
Merged
Conversation
cofin
marked this pull request as draft
May 9, 2026 18:39
cofin
force-pushed
the
chore/v2-repository-deprecation
branch
from
May 9, 2026 18:46
fcc763c to
7c84ed6
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v2 #4758 +/- ##
==========================================
- Coverage 98.20% 98.12% -0.08%
==========================================
Files 349 355 +6
Lines 16044 16177 +133
Branches 1783 1792 +9
==========================================
+ Hits 15756 15874 +118
- Misses 146 160 +14
- Partials 142 143 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cofin
marked this pull request as ready for review
May 9, 2026 19:01
cofin
commented
May 9, 2026
cofin
enabled auto-merge (squash)
May 9, 2026 19:25
This was referenced May 10, 2026
cofin
added a commit
that referenced
this pull request
May 11, 2026
…ns.minijinja (#4760) Moves the MiniJinja template engine integration from `litestar.contrib.minijinja` to `litestar.plugins.minijinja`, and removes the contrib path on `main`. A follow-up PR onto `v2` will add a deprecation shim covering both public and private symbols. Same shape as the OTel split (#4691 + #4759) and the repository split (#4735 + #4758). `litestar/plugins/flash.py` lazily imports the private `_transform_state` from MiniJinja, so any deprecation shim has to forward private symbols. That diagnosis came from @xronocode's audit in #4754; this PR preserves it by migrating flash.py before deleting contrib, so every intermediate commit keeps the dependency graph valid. Salvages the contrib tests into `tests/unit/test_plugins/test_minijinja.py` (98% coverage), migrates every internal call site, and adds `docs/reference/plugins/minijinja.rst`. Closes #4718. Co-authored-by: xronocode <myevdokimov@gmail.com>
cofin
added a commit
that referenced
this pull request
May 11, 2026
…4764) Moves the Mako template engine integration from `litestar.contrib.mako` to `litestar.plugins.mako`, and removes the contrib path on `main`. A follow-up PR onto `v2` will add a deprecation shim, giving 2.x users a migration window. Same shape as the OTel split (#4691 + #4759) and the repository split (#4735 + #4758). Implementation reference: PR #4753 by @xronocode. Every commit carries a co-author trailer. Salvages the contrib tests into `tests/unit/test_plugins/test_mako.py`, migrates every internal call site (csrf middleware, flash, template suite), and adds `docs/reference/plugins/mako.rst`. Closes #4717. Co-authored-by: xronocode <myevdokimov@gmail.com>
cofin
added a commit
that referenced
this pull request
May 13, 2026
…#4762) Moves the Jinja2 template engine integration from `litestar.contrib.jinja` to `litestar.plugins.jinja`, and removes the contrib path on `main`. A follow-up PR onto `v2` will add a deprecation shim, giving 2.x users a migration window. Same shape as the OTel split (#4691 + #4759) and the repository split (#4735 + #4758). Implementation reference: PR #4752 by @xronocode. Every commit carries a co-author trailer. Salvages the contrib tests into `tests/unit/test_plugins/test_jinja.py`, migrates every internal call site (csrf middleware, flash, template suite, htmx examples), and adds `docs/reference/plugins/jinja.rst`. Closes #4716. Co-authored-by: xronocode <myevdokimov@gmail.com>
provinzkraut
approved these changes
May 14, 2026
Add PEP 562 __getattr__ shims to every public entry under litestar.repository.* matching the v2 contrib.repository deprecation style: minimal __getattr__ that lazy-imports from the canonical destination (advanced_alchemy.X) with a fallback to the existing private _filters/_exceptions modules when advanced_alchemy is not installed. Files touched (no new internal modules introduced): - litestar/repository/__init__.py (Pattern A shim) - litestar/repository/exceptions.py - litestar/repository/filters.py - litestar/repository/handlers.py (lazy build inside __getattr__) - litestar/repository/abc/__init__.py - litestar/repository/testing/__init__.py - litestar/repository/abc/_async.py / _sync.py (rebound to advanced_alchemy.exceptions to avoid self-triggering the shim) - litestar/repository/testing/generic_mock_repository.py (same) version='2.22.0', removal_in='3.0.0' on every warn_deprecation call; matching '.. deprecated:: 2.22.0' directives on the three RST reference pages. v2 changelog entry under a new 2.22.0 release block. Tests inline in tests/unit/test_deprecations.py — added a parametrized test_litestar_repository_deprecations covering all 25 public entry points (each one fires DeprecationWarning, names the alternative, and resolves to the same object as the canonical advanced_alchemy target).
…build (1) Remove two 'type: ignore[assignment]' suppressions that mypy now flags as unused: in litestar/repository/__init__.py and in testing/generic_mock_repository.py. Both fallbacks are reached only when advanced_alchemy is not installed (covered by 'pragma: no cover'). (2) Replace the broken intersphinx reference ':ref:`advanced-alchemy:usage/frameworks/litestar:Session Middleware`' with literal prose. The label does not exist in the advanced-alchemy docs and was failing 'build-docs -W'. The reference was already failing on 2.21.x but only surfaced under -W; both v2 cherry-pick PRs need it clean for CI.
- generic_mock_repository.py: move FilterTypes import to TYPE_CHECKING block (TC001) and add type: ignore on the _exceptions fallback so the fallback's RepositoryError type assignment matches the advanced_alchemy branch. - changelog: change :type: deprecation to :type: misc since the v2 changelog directive only accepts feature/bugfix/misc; reference PR 4758. - test_opentelemetry.py: suppress pyright's pre-existing reportGeneralTypeIssues errors on the after_exception_hook tuple-unpack assertions (older pyright on v2 can't narrow Exception/Scope through tuple destructuring).
- abc.rst, handlers.rst: 'removed before 3.0.0 GA' -> 'removed before 3.0.0'. - changelog.rst: 'removed in Litestar 3.0.0' -> 'removed before 3.0.0' to match the directives. - test_deprecations.py: parametrized AttributeError test across all six shim modules so codecov's patch target stops missing the 'attr_name not in __all__' branch on litestar.repository.abc and litestar.repository.testing.
advanced_alchemy ships SQLAlchemyAsyncMockRepository / SQLAlchemySyncMockRepository under advanced_alchemy.repository.memory, so the testing shim isn't a no-replacement deprecation — name the AA classes in the warning message and the docs. - testing/__init__.py: add _ALTERNATIVES mapping, pass alternative= to warn_deprecation so the warning text includes the AA path. - testing.rst: replace 'no replacement' note with the AA class references. - changelog: replace the 'no replacement; rewrite tests' sentence with the AA class references. - test_deprecations.py: assert the warning text names the AA path for the testing items, and keep the identity check for items where the shim genuinely returns the AA class (not the testing items, which still hand back the litestar mock during the deprecation window).
…refs
advanced_alchemy's intersphinx inventory only exposes parameters under
its repository module, not the classes themselves. Following the same
pattern already in place for SQLAlchemyAsyncRepository, add nitpick
ignores for SQLAlchemySyncRepository plus the two MockRepository
classes referenced from docs/reference/repository/{abc,testing}.rst.
provinzkraut
force-pushed
the
chore/v2-repository-deprecation
branch
from
May 17, 2026 12:20
078fb14 to
d8ed676
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This deprecates
litestar.repositoryin favor ofadvanced_alchemy. Thelitestar.repositorymodule — including itsfilters,exceptions,handlers,abc, andtestingsubmodules — will be removed before 3.0.0, and this lands the deprecation on the v2 line so users have a release to migrate against.The new home for everything is
advanced_alchemy:advanced_alchemy.filtersfor the filter typesadvanced_alchemy.exceptionsfor the repository exceptionsadvanced_alchemy.repository.SQLAlchemyAsyncRepository/SQLAlchemySyncRepositoryfor the abstract base classesadvanced_alchemy.repository.memory.SQLAlchemyAsyncMockRepository/SQLAlchemySyncMockRepositoryfor the generic mock underlitestar.repository.testingEach public symbol's warning text spells out exactly what to import instead, so users get a one-line fix from the
DeprecationWarningitself.Under the hood this is PEP 562
__getattr__shims at every submodule entry point. Importinglitestar.repositoryis silent; only attribute access fires the warning, so test runs that touch the package transitively don't get spammed.Documentation gets a
.. deprecated:: 2.22.0notice on each of the three reference pages, and there's a changelog entry under a new2.22.0block. A parametrized test intests/unit/test_deprecations.pyasserts every public symbol firesDeprecationWarningand that the message names theadvanced_alchemytarget.Note on
nitpick_ignoreThe deprecation notes cross-reference
advanced_alchemyclasses via:class:directives. Those can't be resolved through intersphinx right now — advanced-alchemy'sobjects.invis missingpy:classentries for everything underadvanced_alchemy.repositoryandadvanced_alchemy.repository.memory(onlypy:parameterentries are indexed). Filed upstream as advanced-alchemy#729.As a temporary workaround, this PR adds three entries to
nitpick_ignoreindocs/conf.py, matching the existing entry forSQLAlchemyAsyncRepository:advanced_alchemy.repository.SQLAlchemySyncRepositoryadvanced_alchemy.repository.memory.SQLAlchemyAsyncMockRepositoryadvanced_alchemy.repository.memory.SQLAlchemySyncMockRepositoryOnce the upstream fix ships and the v3.x line picks up the new inventory, those entries can be removed.
Closes #4721 once merged. The main-side migration of in-tree callers landed in #4735.
📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4758