Skip to content

Commit d660a7f

Browse files
fix circular dependencies
1 parent fc9ae80 commit d660a7f

File tree

9 files changed

+41
-50
lines changed

9 files changed

+41
-50
lines changed

src/quart_sqlalchemy/sim/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from quart import Response
1313
from quart_schema import QuartSchema
1414

15-
from .. import Base
16-
from .. import SQLAlchemyConfig
17-
from ..framework import QuartSQLAlchemy
18-
from .util import ObjectID
15+
from quart_sqlalchemy import Base
16+
from quart_sqlalchemy import SQLAlchemyConfig
17+
from quart_sqlalchemy.framework import QuartSQLAlchemy
18+
from quart_sqlalchemy.sim.util import ObjectID
1919

2020

2121
AUTHORIZATION_PATTERN = re.compile(r"Bearer (?P<token>.+)")

src/quart_sqlalchemy/sim/handle.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
from sqlalchemy.orm import Session
66

77
from quart_sqlalchemy import Bind
8-
9-
from . import signals
10-
from .logic import LogicComponent as Logic
11-
from .model import AuthUser
12-
from .model import AuthWallet
13-
from .model import EntityType
14-
from .model import WalletType
15-
from .util import ObjectID
8+
from quart_sqlalchemy.sim import signals
9+
from quart_sqlalchemy.sim.logic import LogicComponent as Logic
10+
from quart_sqlalchemy.sim.model import AuthUser
11+
from quart_sqlalchemy.sim.model import AuthWallet
12+
from quart_sqlalchemy.sim.model import EntityType
13+
from quart_sqlalchemy.sim.model import WalletType
14+
from quart_sqlalchemy.sim.util import ObjectID
1615

1716

1817
logger = logging.getLogger(__name__)

src/quart_sqlalchemy/sim/logic.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,22 @@
33
from datetime import datetime
44
from functools import wraps
55

6-
from pydantic import BaseModel
7-
from pydantic import Field
86
from sqlalchemy import or_
9-
from sqlalchemy import ScalarResult
107
from sqlalchemy.orm import contains_eager
11-
from sqlalchemy.orm import DeclarativeBase
12-
from sqlalchemy.orm import selectinload
138
from sqlalchemy.orm import Session
149
from sqlalchemy.sql.expression import func
15-
from sqlalchemy.sql.expression import label
16-
17-
from quart_sqlalchemy.model import Base
18-
from quart_sqlalchemy.types import ColumnExpr
19-
from quart_sqlalchemy.types import EntityIdT
20-
from quart_sqlalchemy.types import EntityT
21-
from quart_sqlalchemy.types import ORMOption
22-
from quart_sqlalchemy.types import Selectable
23-
24-
from . import signals
25-
from .model import AuthUser as auth_user_model
26-
from .model import AuthWallet as auth_wallet_model
27-
from .model import ConnectInteropStatus
28-
from .model import EntityType
29-
from .model import MagicClient as magic_client_model
30-
from .model import Provenance
31-
from .model import WalletType
32-
from .repo import SQLAlchemyRepository
33-
from .repo_adapter import RepositoryLegacyAdapter
34-
from .util import ObjectID
35-
from .util import one
10+
11+
from quart_sqlalchemy.sim import signals
12+
from quart_sqlalchemy.sim.model import AuthUser as auth_user_model
13+
from quart_sqlalchemy.sim.model import AuthWallet as auth_wallet_model
14+
from quart_sqlalchemy.sim.model import ConnectInteropStatus
15+
from quart_sqlalchemy.sim.model import EntityType
16+
from quart_sqlalchemy.sim.model import MagicClient as magic_client_model
17+
from quart_sqlalchemy.sim.model import Provenance
18+
from quart_sqlalchemy.sim.model import WalletType
19+
from quart_sqlalchemy.sim.repo_adapter import RepositoryLegacyAdapter
20+
from quart_sqlalchemy.sim.util import ObjectID
21+
from quart_sqlalchemy.sim.util import one
3622

3723

3824
logger = logging.getLogger(__name__)

src/quart_sqlalchemy/sim/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from .app import app
2-
from .views import api
1+
from quart_sqlalchemy.sim.app import app
2+
from quart_sqlalchemy.sim.views import api
33

44

5-
app.register_blueprint(api)
5+
app.register_blueprint(api, url_prefix="/v1")
66

77

88
if __name__ == "__main__":
9-
app.run(port=8080)
9+
app.run(port=8081)

src/quart_sqlalchemy/sim/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class MagicClient(db.Model, SoftDeleteMixin, TimestampMixin):
8181
is_signing_modal_enabled: Mapped[bool] = sa.orm.mapped_column(default=False)
8282
global_audience_enabled: Mapped[bool] = sa.orm.mapped_column(default=False)
8383

84-
public_api_key: Mapped[str] = sa.orm.mapped_column(default_factory=secrets.token_hex)
85-
secret_api_key: Mapped[str] = sa.orm.mapped_column(default_factory=secrets.token_hex)
84+
public_api_key: Mapped[str] = sa.orm.mapped_column(default=secrets.token_hex)
85+
secret_api_key: Mapped[str] = sa.orm.mapped_column(default=secrets.token_hex)
8686

8787
auth_users: Mapped[t.List["AuthUser"]] = sa.orm.relationship(
8888
back_populates="magic_client",
@@ -144,7 +144,7 @@ def is_magic_connect_user(self):
144144

145145

146146
class AuthWallet(db.Model, SoftDeleteMixin, TimestampMixin):
147-
__tablename__ = "auth_user"
147+
__tablename__ = "auth_wallet"
148148

149149
id: Mapped[ObjectID] = sa.orm.mapped_column(primary_key=True, autoincrement=True)
150150
auth_user_id: Mapped[ObjectID] = sa.orm.mapped_column(sa.ForeignKey("auth_user.id"))

src/quart_sqlalchemy/sim/repo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
import sqlalchemy.orm
1111
import sqlalchemy.sql
1212

13+
from quart_sqlalchemy.sim.builder import StatementBuilder
1314
from quart_sqlalchemy.types import ColumnExpr
1415
from quart_sqlalchemy.types import EntityIdT
1516
from quart_sqlalchemy.types import EntityT
1617
from quart_sqlalchemy.types import ORMOption
1718
from quart_sqlalchemy.types import Selectable
1819
from quart_sqlalchemy.types import SessionT
1920

20-
from .builder import StatementBuilder
21-
2221

2322
sa = sqlalchemy
2423

@@ -56,7 +55,6 @@ def identity(self) -> t.Type[EntityIdT]:
5655
return self.__orig_class__.__args__[1] # type: ignore
5756

5857

59-
6058
class SQLAlchemyRepository(
6159
AbstractRepository[EntityT, EntityIdT],
6260
t.Generic[EntityT, EntityIdT],

src/quart_sqlalchemy/sim/repo_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from quart_sqlalchemy.types import ORMOption
1313
from quart_sqlalchemy.types import Selectable
1414

15-
from .repo import SQLAlchemyRepository
15+
from quart_sqlalchemy.sim.repo import SQLAlchemyRepository
1616

1717

1818
class BaseModelSchema(BaseModel):

src/quart_sqlalchemy/sim/schema.py

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

33
from pydantic import BaseModel
44

5-
from .util import ObjectID
5+
from quart_sqlalchemy.sim.util import ObjectID
66

77

88
class BaseSchema(BaseModel):

src/quart_sqlalchemy/sqla.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def initialize(self):
3838
class Model(self.config.model_class, sa.orm.DeclarativeBase):
3939
pass
4040

41+
type_annotation_map = {}
42+
for base_class in Model.__mro__[::-1]:
43+
if base_class is Model:
44+
continue
45+
base_map = getattr(base_class, "type_annotation_map", {}).copy()
46+
type_annotation_map.update(base_map)
47+
48+
Model.registry.type_annotation_map.update(type_annotation_map)
4149
self.Model = Model
4250

4351
self.binds = {}

0 commit comments

Comments
 (0)