Skip to content

Engine AC doesn't contain start/close_connection_pool() method. #1

@gmos

Description

@gmos
@app.on_event("startup")
async def open_database_connection_pool():
    engine = engine_finder()
    await engine.start_connection_pool()


@app.on_event("shutdown")
async def close_database_connection_pool():
    engine = engine_finder()
    await engine.close_connection_pool()

This code is in many of the sample applications. The engine_finder() is typed as Engine, which is an abstract class. It doesn't however provide an (@abstract)method for start_connection_pool() and close_connection_pool(). These methods only exist in the concrete subclass for Postgres. Hence vscode/pylance complain about non-existing methods.

I can do a PR, but am unsure about best solution.
Personally I would add these methods as normal methods to the Engine class, just providing a colored_warning() that pooling is not implemented for the provided engine.

Alternatively all sample programs using the connection pool could be changed like:

@app.on_event("startup")
async def open_database_connection_pool():
    engine = engine_finder()
    if isinstance(engine, PostgresEngine):
        await engine.start_connection_pool()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions