Skip to content

Cannot pass pool instance via bind configuration #1421

@bricct

Description

@bricct

When using Flask SQLAlchemy to federate calls to create_engine whilst also passing in an instance of Pool via the bind configuration option pool=my_pool, Flask SQLAlchemy will always set echo_pool to either False or True in the kwargs to create_engine internally.

When SQLAlchemy creates an engine from a pre-instantiated Pool object, it does not consume the echo_pool kwarg and as a result fails to create the engine as it fails to assert that all kwargs were consumed.

To reproduce:

import sqlite3
import sqlalchemy as sa

pool = sa.pool.StaticPool(creator=lambda: sqlite3.connect(":memory:"))
app.config["SQLALCHEMY_BINDS"] = {"a": {"url": "sqlite://", "pool": pool}}
db = SQLAlchemy(app, model_class=model_class)
assert db.engines["a"].pool is pool
.venv/lib/python3.13/site-packages/flask_sqlalchemy/extension.py:278: in __init__
    self.init_app(app)
.venv/lib/python3.13/site-packages/flask_sqlalchemy/extension.py:374: in init_app
    engines[key] = self._make_engine(key, options, app)
.venv/lib/python3.13/site-packages/flask_sqlalchemy/extension.py:665: in _make_engine
    return sa.engine_from_config(options, prefix="")
.venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py:820: in engine_from_config
    return create_engine(url, **options)
.venv/lib/python3.13/site-packages/sqlalchemy/util/deprecations.py:281: in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
.venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py:697: in create_engine
    raise TypeError(
E   TypeError: Invalid argument(s) 'echo_pool' sent to create_engine(), using configuration PGDialect_psycopg2/StaticPool/Engine.  Please check that the keyword arguments are appropriate for this combination of components.

I would expect this to not error via not setting echo_pool in the kwargs when pool is passed via the bind config.

Environment:

  • Python version: 3.13.11
  • Flask-SQLAlchemy version: 3.1.1
  • SQLAlchemy version: 2.0.49

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