You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are no similar issues or pull requests for this yet.
Is your feature related to a problem? Please describe.
I want to setup sqladmin for project in which we're using google IAM auth for PostgreSQL and our function that creates SqlAlchemy engine is async:
fromtypingimportTYPE_CHECKINGfromgoogle.cloud.sql.connectorimportConnector, create_async_connectorfromsqlalchemy.ext.asyncioimportAsyncEngine, create_async_engineifTYPE_CHECKING:
fromasyncpgimportConnectionclassAsyncEngineWrapper:
""" Reflects the interface of the AsyncEngine but have reference to the Cloud SQL Connector to close it properly when disposing the engine. """def__init__(self, engine: AsyncEngine, connector: Connector):
self.engine=engineself.connector=connectordef__getattr__(self, attr):
returngetattr(self.engine, attr)
asyncdefdispose(self, close: bool=False) ->None:
awaitself.connector.close_async()
awaitself.engine.dispose(close)
asyncdefcreate_cloud_sql_async_engine(
cloud_sql_instance: str,
*,
cloud_sql_user: str,
cloud_sql_database: str,
cloud_sql_password: str|None=None,
enable_iam_auth: bool=True,
**kwargs,
) ->AsyncEngine:
""" Use Cloud SQL IAM role authentication mechanism https://cloud.google.com/sql/docs/postgres/iam-authentication to create new SqlAlchemy async engine. """connector=awaitcreate_async_connector()
asyncdefget_conn() ->"Connection":
returnawaitconnector.connect_async(
cloud_sql_instance,
"asyncpg",
user=cloud_sql_user,
password=cloud_sql_password,
db=cloud_sql_database,
enable_iam_auth=enable_iam_auth,
)
engine=create_async_engine(
"postgresql+asyncpg://", async_creator=get_conn, **kwargs
)
returnAsyncEngineWrapper(engine, connector) # type: ignore[return-value]
and now it's quite tricky to get an instance of the engine when creating FastAPI app (and Admin instance).
Similar problem might have someone that share connection pool between app and admin and creates engine inside of the lifespan https://fastapi.tiangolo.com/advanced/events/ - which happens after FastAPI app is created.
Describe the solution you would like.
I would like to have an option to create app with an admin instance without passing engine or sessionmaker yet. and then have an option (like dedicated Admin method) to set proper sessionmaker or engine inside of the lifespan. Something like:
I tried to create whole Admin inside of the lifespan but it didn't work. It looks like it's already too late and we need to set it up when creating FastAPI app.
Additional context
No response
The text was updated successfully, but these errors were encountered:
Checklist
Is your feature related to a problem? Please describe.
I want to setup sqladmin for project in which we're using google IAM auth for PostgreSQL and our function that creates SqlAlchemy engine is async:
and now it's quite tricky to get an instance of the engine when creating FastAPI app (and Admin instance).
Similar problem might have someone that share connection pool between app and admin and creates engine inside of the lifespan https://fastapi.tiangolo.com/advanced/events/ - which happens after FastAPI app is created.
Describe the solution you would like.
I would like to have an option to create app with an admin instance without passing engine or sessionmaker yet. and then have an option (like dedicated Admin method) to set proper sessionmaker or engine inside of the
lifespan
. Something like:Describe alternatives you considered
I tried to create whole Admin inside of the
lifespan
but it didn't work. It looks like it's already too late and we need to set it up when creating FastAPI app.Additional context
No response
The text was updated successfully, but these errors were encountered: