Skip to content

Commit 9206e55

Browse files
committed
Rename model_declarative_base to avoid conflicts with pydantic v2 models model_ attribute namespace
1 parent 0c17771 commit 9206e55

File tree

10 files changed

+16
-16
lines changed

10 files changed

+16
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Example:
7272
bind = sa_manager.get_bind()
7373

7474

75-
class MyModel(bind.model_declarative_base):
75+
class MyModel(bind.declarative_base):
7676
pass
7777

7878

@@ -144,7 +144,7 @@ The `SQLAlchemyRepository` and `SQLAlchemyAsyncRepository` class can be used dir
144144
from sqlalchemy_bind_manager.repository import SQLAlchemyRepository
145145

146146

147-
class MyModel(model_declarative_base):
147+
class MyModel(declarative_base):
148148
pass
149149

150150
# Direct usage

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ config = SQLAlchemyConfig(
6161
sa_manager = SQLAlchemyBindManager(config)
6262

6363
# Declare a model
64-
class MyModel(sa_manager.get_bind().model_declarative_base):
64+
class MyModel(sa_manager.get_bind().declarative_base):
6565
id: Mapped[int] = mapped_column(primary_key=True)
6666
name: Mapped[str] = mapped_column(String(30))
6767

docs/manager/alembic/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
sa_manager = SQLAlchemyBindManager(config=bind_config)
2929

30-
class BookModel(sa_manager.get_bind().model_declarative_base):
30+
class BookModel(sa_manager.get_bind().declarative_base):
3131
id = Column(Integer)
3232
title = Column(String)
3333
################################################################

docs/manager/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Once the bind manager is initialised we can retrieve and use the SQLAlchemyBind
2323
The `SQLAlchemyBind` class has the following attributes:
2424

2525
* `engine`: The initialised SQLALchemy `Engine`
26-
* `model_declarative_base`: A base class that can be used to create [declarative models](https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#declarative-mapping)
26+
* `declarative_base`: A base class that can be used to create [declarative models](https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#declarative-mapping)
2727
* `registry_mapper`: The `registry` associated with the `engine`. It can be used with Alembic or to setup [imperative mapping](https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#imperative-mapping)
2828
* `session_class`: The class built by [sessionmaker()](https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.sessionmaker), either `Session` or `AsyncSession`
2929

docs/manager/models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from sqlalchemy import String
1010

1111
bind = sa_manager.get_bind()
1212

13-
class MyModel(bind.model_declarative_base):
13+
class MyModel(bind.declarative_base):
1414
id: Mapped[int] = mapped_column(primary_key=True)
1515
name: Mapped[str] = mapped_column(String(30))
1616
```

docs/repository/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The `SQLAlchemyRepository` and `SQLAlchemyAsyncRepository` class can be used dir
66
from sqlalchemy_bind_manager.repository import SQLAlchemyRepository
77

88

9-
class MyModel(model_declarative_base):
9+
class MyModel(declarative_base):
1010
pass
1111

1212
# Direct usage

sqlalchemy_bind_manager/_bind_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
create_async_engine,
1111
)
1212
from sqlalchemy.orm import Session, sessionmaker
13-
from sqlalchemy.orm.decl_api import registry
13+
from sqlalchemy.orm.decl_api import DeclarativeMeta, registry
1414

1515
from sqlalchemy_bind_manager.exceptions import (
1616
InvalidConfig,
@@ -32,7 +32,7 @@ class SQLAlchemyAsyncConfig(BaseModel):
3232

3333
class SQLAlchemyBind(BaseModel):
3434
engine: Engine
35-
model_declarative_base: type
35+
declarative_base: DeclarativeMeta
3636
registry_mapper: registry
3737
session_class: sessionmaker[Session]
3838

@@ -42,7 +42,7 @@ class Config:
4242

4343
class SQLAlchemyAsyncBind(BaseModel):
4444
engine: AsyncEngine
45-
model_declarative_base: type
45+
declarative_base: DeclarativeMeta
4646
registry_mapper: registry
4747
session_class: async_sessionmaker[AsyncSession]
4848

@@ -123,7 +123,7 @@ def __build_sync_bind(
123123
class_=Session,
124124
**session_options,
125125
),
126-
model_declarative_base=registry_mapper.generate_base(),
126+
declarative_base=registry_mapper.generate_base(),
127127
)
128128

129129
def __build_async_bind(
@@ -141,7 +141,7 @@ def __build_async_bind(
141141
bind=engine,
142142
**session_options,
143143
),
144-
model_declarative_base=registry_mapper.generate_base(),
144+
declarative_base=registry_mapper.generate_base(),
145145
)
146146

147147
def get_binds(self) -> Mapping[str, Union[SQLAlchemyBind, SQLAlchemyAsyncBind]]:

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def sa_bind(request, sa_manager):
102102

103103
@pytest.fixture
104104
async def model_classes(sa_bind) -> Tuple[Type, Type]:
105-
class ParentModel(sa_bind.model_declarative_base):
105+
class ParentModel(sa_bind.declarative_base):
106106
__tablename__ = "parent_model"
107107
# required in order to access columns with server defaults
108108
# or SQL expression defaults, subsequent to a flush, without
@@ -119,7 +119,7 @@ class ParentModel(sa_bind.model_declarative_base):
119119
lazy="selectin",
120120
)
121121

122-
class ChildModel(sa_bind.model_declarative_base):
122+
class ChildModel(sa_bind.declarative_base):
123123
__tablename__ = "child_model"
124124
# required in order to access columns with server defaults
125125
# or SQL expression defaults, subsequent to a flush, without

tests/repository/test_composite_pk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def sa_manager() -> SQLAlchemyBindManager:
2626
def model_class_composite_pk(sa_manager) -> Type:
2727
default_bind = sa_manager.get_bind()
2828

29-
class MyModel(default_bind.model_declarative_base):
29+
class MyModel(default_bind.declarative_base):
3030
__tablename__ = "mymodel"
3131
# required in order to access columns with server defaults
3232
# or SQL expression defaults, subsequent to a flush, without

tests/repository/test_cursor_paginated_find.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@pytest.fixture
99
async def model_class_string_pk(sa_bind):
10-
class MyModel(sa_bind.model_declarative_base):
10+
class MyModel(sa_bind.declarative_base):
1111
__tablename__ = "mymodel_string_pk"
1212

1313
model_id = Column(String, primary_key=True)

0 commit comments

Comments
 (0)