Skip to content

Commit 08297fd

Browse files
authored
feat(v3)!: Remove all SQLAlchemy modules in favor of direct advanced-alchemy imports (#4340)
## Summary This PR completes the deprecation and migration of SQLAlchemy functionality from Litestar v3.0. Following the approach from PR #4225, **both** `litestar.contrib.sqlalchemy` and `litestar.plugins.sqlalchemy` modules have been completely removed. Users must now import directly from `advanced_alchemy.extensions.litestar`. ## Related Issues/PRs - Closes #4163 - Second removal attempt - Related to #4225 - Previous near-perfect implementation (out of sync with master) - Related to #4069 - Initial removal attempt by @provinzkraut - Related to #3755 - Original deprecation PR ## Breaking Changes **BREAKING CHANGE**: All SQLAlchemy functionality has been removed from Litestar. ### Migration Guide - `from litestar.contrib.sqlalchemy import X` → `from advanced_alchemy.extensions.litestar import X` - `from litestar.plugins.sqlalchemy import Y` → `from advanced_alchemy.extensions.litestar import Y` - `from litestar.plugins.sqlalchemy.base import Z` → `from advanced_alchemy.extensions.litestar.base import Z` ## Changes Made 1. **Complete Module Removal**: - Removed entire `litestar/contrib/sqlalchemy/` directory tree - Removed `litestar/plugins/sqlalchemy.py` re-export file 2. **Documentation Updates**: Updated all example files to use `advanced_alchemy.extensions.litestar` imports 3. **Test Updates**: - Updated all tests to use new import paths - Deleted tests for deprecated functionality that no longer exists 4. **Clean Architecture**: No re-export layer in Litestar - direct imports from advanced-alchemy only 5. **Changelog**: Added breaking change entry explaining the migration ## Technical Implementation This implementation follows the cleaner approach from PR #4225: - **No re-export layers** - users import directly from `advanced_alchemy.extensions.litestar` - **Complete separation of concerns** - Litestar no longer maintains SQLAlchemy code - **Single source of truth** - advanced-alchemy is the sole provider of SQLAlchemy integration ## Benefits 1. **Cleaner separation** - Litestar doesn't maintain SQLAlchemy code 2. **Single source of truth** - advanced-alchemy is the only place for SQLAlchemy integration 3. **Easier maintenance** - No need to keep re-export layers in sync 4. **Clear dependency** - Users know they need advanced-alchemy for SQLAlchemy support ## Testing - ✅ All tests pass - ✅ Type checking passes (mypy and pyright) - ✅ Linting passes - ✅ Documentation examples work with new imports - ✅ SQLAlchemy example tests pass ## Coordination Note This work was coordinated after PR #4337 (removing `litestar.contrib.repository`) was merged.
1 parent 510b202 commit 08297fd

116 files changed

Lines changed: 622 additions & 2162 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/conf.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@
148148
(PY_CLASS, "NoneType"),
149149
(PY_CLASS, "litestar._openapi.schema_generation.schema.SchemaCreator"),
150150
(PY_CLASS, "litestar._signature.model.SignatureModel"),
151-
(PY_CLASS, "litestar.contrib.sqlalchemy.plugins.init.config.compat._CreateEngineMixin"),
152151
(PY_CLASS, "litestar.utils.signature.ParsedSignature"),
153152
(PY_CLASS, "litestar.utils.sync.AsyncCallable"),
154153
# types in changelog that no longer exist
155154
(PY_ATTR, "litestar.dto.factory.DTOConfig.underscore_fields_private"),
156155
(PY_CLASS, "anyio.abc.BlockingPortal"),
157156
(PY_CLASS, "litestar.contrib.msgspec.MsgspecDTO"),
157+
(PY_CLASS, "litestar.contrib.sqlalchemy.types.JsonB"),
158+
(PY_CLASS, "litestar.contrib.sqlalchemy.plugins.SQLAlchemyInitPlugin"),
158159
(PY_CLASS, "litestar.contrib.repository.filters.NotInCollectionFilter"),
159160
(PY_CLASS, "litestar.contrib.repository.filters.NotInSearchFilter"),
160161
(PY_CLASS, "litestar.contrib.repository.filters.OnBeforeAfter"),
@@ -168,12 +169,7 @@
168169
(PY_CLASS, "litestar.response.RedirectResponse"),
169170
(PY_CLASS, "litestar.response_containers.Redirect"),
170171
(PY_CLASS, "litestar.response_containers.Template"),
171-
(PY_CLASS, "litestar.contrib.sqlalchemy.plugins.SQLAlchemyPlugin"),
172-
(PY_CLASS, "litestar.contrib.sqlalchemy.plugins.SQLAlchemySerializationPlugin"),
173-
(PY_CLASS, "litestar.contrib.sqlalchemy.plugins.SQLAlchemyInitPlugin"),
174-
(PY_CLASS, "litestar.contrib.sqlalchemy.dto.SQLAlchemyDTO"),
175-
(PY_CLASS, "litestar.contrib.sqlalchemy.types.BigIntIdentity"),
176-
(PY_CLASS, "litestar.contrib.sqlalchemy.types.JsonB"),
172+
(PY_CLASS, "litestar.contrib.htmx.request.HTMXRequest"),
177173
(PY_CLASS, "litestar.typing.ParsedType"),
178174
(PY_METH, "litestar.dto.factory.DTOData.create_instance"),
179175
(PY_METH, "litestar.dto.interface.DTOInterface.data_to_encodable_type"),
@@ -208,6 +204,8 @@
208204
(PY_CLASS, "advanced_alchemy.base.UUIDAuditBase"),
209205
(PY_CLASS, "advanced_alchemy.base.BigIntBase"),
210206
(PY_CLASS, "advanced_alchemy.base.BigIntAuditBase"),
207+
(PY_CLASS, "advanced_alchemy.extensions.litestar.plugins.SQLAlchemySerializationPlugin"),
208+
(PY_CLASS, "advanced_alchemy.extensions.litestar.plugins.SQLAlchemyInitPlugin"),
211209
]
212210

213211
nitpick_ignore_regex = [
@@ -220,7 +218,6 @@
220218
(PY_RE, r".*UserType"),
221219
(PY_RE, r"ModelT"),
222220
(PY_RE, r"litestar.*\.T"),
223-
(PY_RE, r"litestar.contrib.sqlalchemy.repository.ModelT"),
224221
(PY_RE, r"litestar\.middleware\.session\.base\.BaseSessionBackendT"),
225222
(PY_RE, r"litestar\.types.*"),
226223
(PY_RE, r"httpx.*"),

docs/examples/data_transfer_objects/factory/enveloping_return_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from datetime import datetime
33
from typing import Generic, TypeVar
44

5+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
56
from sqlalchemy.orm import Mapped
67

78
from litestar import Litestar, get
89
from litestar.dto import DTOConfig
9-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
1010

1111
from .my_lib import Base
1212

docs/examples/data_transfer_objects/factory/excluding_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from typing import Annotated
33
from uuid import UUID
44

5+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
56
from sqlalchemy import ForeignKey
67
from sqlalchemy.orm import Mapped, mapped_column, relationship
78

89
from litestar import Litestar, post
910
from litestar.dto import DTOConfig, dto_field
10-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
1111

1212
from .my_lib import Base
1313

docs/examples/data_transfer_objects/factory/included_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from typing import Annotated
33
from uuid import UUID
44

5+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
56
from sqlalchemy import ForeignKey
67
from sqlalchemy.orm import Mapped, mapped_column, relationship
78

89
from litestar import Litestar, post
910
from litestar.dto import DTOConfig, dto_field
10-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
1111

1212
from .my_lib import Base
1313

docs/examples/data_transfer_objects/factory/marking_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from datetime import datetime
22

3+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
34
from sqlalchemy.orm import Mapped, mapped_column
45

56
from litestar import Litestar, post
67
from litestar.dto import dto_field
7-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
88

99
from .my_lib import Base
1010

docs/examples/data_transfer_objects/factory/my_lib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
from typing import Any
44

5+
from advanced_alchemy.extensions.litestar import base, mixins
56
from sqlalchemy.orm import DeclarativeBase
67

7-
from litestar.plugins.sqlalchemy import base, mixins
8-
98

109
class _Base(base.CommonTableAttributes, mixins.UUIDPrimaryKey, DeclarativeBase):
1110
"""Fake base SQLAlchemy model for typing purposes."""

docs/examples/data_transfer_objects/factory/paginated_return_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from datetime import datetime
22

3+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
34
from sqlalchemy.orm import Mapped
45

56
from litestar import Litestar, get
67
from litestar.dto import DTOConfig
78
from litestar.pagination import ClassicPagination
8-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
99

1010
from .my_lib import Base
1111

docs/examples/data_transfer_objects/factory/related_items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from typing import Annotated
44
from uuid import UUID
55

6+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
67
from sqlalchemy import ForeignKey
78
from sqlalchemy.orm import Mapped, mapped_column, relationship
89

910
from litestar import Litestar, put
1011
from litestar.dto import DTOConfig
11-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
1212

1313
from .my_lib import Base
1414

docs/examples/data_transfer_objects/factory/renaming_all_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from datetime import datetime
22
from typing import Annotated
33

4+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
45
from sqlalchemy.orm import Mapped, mapped_column
56

67
from litestar import Litestar, post
78
from litestar.dto import DTOConfig, dto_field
8-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
99

1010
from .my_lib import Base
1111

docs/examples/data_transfer_objects/factory/renaming_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from datetime import datetime
22
from typing import Annotated
33

4+
from advanced_alchemy.extensions.litestar import SQLAlchemyDTO
45
from sqlalchemy.orm import Mapped, mapped_column
56

67
from litestar import Litestar, post
78
from litestar.dto import DTOConfig, dto_field
8-
from litestar.plugins.sqlalchemy import SQLAlchemyDTO
99

1010
from .my_lib import Base
1111

0 commit comments

Comments
 (0)