I want to do the following:
# __init__.py
from quart import Quart
from quart_sqlalchemy import QuartSQLAlchemyConfig
def create_app() -> Quart:
quart = Quart(__name__)
... # init stuff
db.config = QuartSQLAlchemyConfig(...)
db.init_app(app)
# db.py
from quart_squalchemy import QuartSQLAlchemy
db = QuartSQLAlchemy()
This fails because the QuartSQLAlchemy constructor calls its superclass which calls initialize().
|
class QuartSQLAlchemy(SQLAlchemy): |
|
def __init__( |
|
self, |
|
config: SQLAlchemyConfig, |
|
app: t.Optional[Quart] = None, |
|
): |
|
super().__init__(config) |
|
if app is not None: |
|
self.init_app(app) |
|
class SQLAlchemy: |
|
config: SQLAlchemyConfig |
|
binds: t.Dict[str, t.Union[Bind, AsyncBind]] |
|
Model: t.Type[sa.orm.DeclarativeBase] |
|
|
|
def __init__(self, config: SQLAlchemyConfig, initialize: bool = True): |
|
self.config = config |
|
|
|
if initialize: |
|
self.initialize() |
A fix for this would be for QuartSQLAlchemy to init like:
def __init__(
self,
config: SQLAlchemyConfig,
app: t.Optional[Quart] = None,
):
super().__init__(config, initialize=app is not None)
if app is not None:
self.init_app(app)
And then for init_app() to call self.initialize() as its first line.
I want to do the following:
This fails because the
QuartSQLAlchemyconstructor calls its superclass which callsinitialize().quart-sqlalchemy/src/quart_sqlalchemy/framework/extension.py
Lines 11 to 19 in d08114d
quart-sqlalchemy/src/quart_sqlalchemy/sqla.py
Lines 22 to 31 in d08114d
A fix for this would be for
QuartSQLAlchemyto init like:And then for
init_app()to callself.initialize()as its first line.