From: Mike Bayer Date: Fri, 14 Jan 2022 22:42:44 +0000 (-0500) Subject: remove dbapi_proxy module X-Git-Tag: rel_2_0_0b1~541^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e058d25cf01c3163e5ff39e4ccaff1928f332a27;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git remove dbapi_proxy module This module was not documented nor part of any test suite, and it's unlikely it was working correctly. It's not likely that this module was ever used after the first year or so of SQLAlchemy, and it's stayed around because it is so obscure that I never remembered to remove it. Change-Id: I0ed9030438982e935add87c51abbfff50e7382be References: #7257 --- diff --git a/doc/build/changelog/unreleased_20/7257.rst b/doc/build/changelog/unreleased_20/7257.rst index 079b0554e9..6dd9a47609 100644 --- a/doc/build/changelog/unreleased_20/7257.rst +++ b/doc/build/changelog/unreleased_20/7257.rst @@ -63,3 +63,6 @@ * Legacy "in-place mutator" methods on :class:`_sql.Select` such as ``append_whereclause()``, ``append_order_by()`` etc are removed. + * Removed the very old "dbapi_proxy" module, which in very early + SQLAlchemy releases was used to provide a transparent connection pool + over a raw DBAPI connection. \ No newline at end of file diff --git a/lib/sqlalchemy/engine/create.py b/lib/sqlalchemy/engine/create.py index a39d981737..7eebb1f019 100644 --- a/lib/sqlalchemy/engine/create.py +++ b/lib/sqlalchemy/engine/create.py @@ -548,9 +548,6 @@ def create_engine(url, **kwargs): pool = poolclass(creator, **pool_args) else: - if isinstance(pool, poollib.dbapi_proxy._DBProxy): - pool = pool.get_pool(*cargs, **cparams) - pool._dialect = dialect # create engine. diff --git a/lib/sqlalchemy/pool/__init__.py b/lib/sqlalchemy/pool/__init__.py index 36982b149b..38059856ee 100644 --- a/lib/sqlalchemy/pool/__init__.py +++ b/lib/sqlalchemy/pool/__init__.py @@ -27,8 +27,6 @@ from .base import PoolProxiedConnection from .base import reset_commit from .base import reset_none from .base import reset_rollback -from .dbapi_proxy import clear_managers -from .dbapi_proxy import manage from .impl import AssertionPool from .impl import AsyncAdaptedQueuePool from .impl import FallbackAsyncAdaptedQueuePool diff --git a/lib/sqlalchemy/pool/dbapi_proxy.py b/lib/sqlalchemy/pool/dbapi_proxy.py deleted file mode 100644 index 3024e6a2fc..0000000000 --- a/lib/sqlalchemy/pool/dbapi_proxy.py +++ /dev/null @@ -1,147 +0,0 @@ -# sqlalchemy/pool/dbapi_proxy.py -# Copyright (C) 2005-2022 the SQLAlchemy authors and contributors -# -# -# This module is part of SQLAlchemy and is released under -# the MIT License: https://www.opensource.org/licenses/mit-license.php - - -"""DBAPI proxy utility. - -Provides transparent connection pooling on top of a Python DBAPI. - -This is legacy SQLAlchemy functionality that is not typically used -today. - -""" - -from .impl import QueuePool -from .. import util -from ..util import threading - -proxies = {} - - -@util.deprecated( - "1.3", - "The :func:`.pool.manage` function is deprecated, and will be " - "removed in a future release.", -) -def manage(module, **params): - r"""Return a proxy for a DB-API module that automatically - pools connections. - - Given a DB-API 2.0 module and pool management parameters, returns - a proxy for the module that will automatically pool connections, - creating new connection pools for each distinct set of connection - arguments sent to the decorated module's connect() function. - - :param module: a DB-API 2.0 database module - - :param poolclass: the class used by the pool module to provide - pooling. Defaults to :class:`.QueuePool`. - - :param \**params: will be passed through to *poolclass* - - """ - try: - return proxies[module] - except KeyError: - return proxies.setdefault(module, _DBProxy(module, **params)) - - -def clear_managers(): - """Remove all current DB-API 2.0 managers. - - All pools and connections are disposed. - """ - - for manager in proxies.values(): - manager.close() - proxies.clear() - - -class _DBProxy: - - """Layers connection pooling behavior on top of a standard DB-API module. - - Proxies a DB-API 2.0 connect() call to a connection pool keyed to the - specific connect parameters. Other functions and attributes are delegated - to the underlying DB-API module. - """ - - def __init__(self, module, poolclass=QueuePool, **kw): - """Initializes a new proxy. - - module - a DB-API 2.0 module - - poolclass - a Pool class, defaulting to QueuePool - - Other parameters are sent to the Pool object's constructor. - - """ - - self.module = module - self.kw = kw - self.poolclass = poolclass - self.pools = {} - self._create_pool_mutex = threading.Lock() - - def close(self): - for key in list(self.pools): - del self.pools[key] - - def __del__(self): - self.close() - - def __getattr__(self, key): - return getattr(self.module, key) - - def get_pool(self, *args, **kw): - key = self._serialize(*args, **kw) - try: - return self.pools[key] - except KeyError: - with self._create_pool_mutex: - if key not in self.pools: - kw.pop("sa_pool_key", None) - pool = self.poolclass( - lambda: self.module.connect(*args, **kw), **self.kw - ) - self.pools[key] = pool - return pool - else: - return self.pools[key] - - def connect(self, *args, **kw): - """Activate a connection to the database. - - Connect to the database using this DBProxy's module and the given - connect arguments. If the arguments match an existing pool, the - connection will be returned from the pool's current thread-local - connection instance, or if there is no thread-local connection - instance it will be checked out from the set of pooled connections. - - If the pool has no available connections and allows new connections - to be created, a new database connection will be made. - - """ - - return self.get_pool(*args, **kw).connect() - - def dispose(self, *args, **kw): - """Dispose the pool referenced by the given connect arguments.""" - - key = self._serialize(*args, **kw) - try: - del self.pools[key] - except KeyError: - pass - - def _serialize(self, *args, **kw): - if "sa_pool_key" in kw: - return kw["sa_pool_key"] - - return tuple(list(args) + [(k, kw[k]) for k in sorted(kw)]) diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index c2ac6637f6..324b971b65 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -68,7 +68,6 @@ def MockDBAPI(): # noqa class PoolTestBase(fixtures.TestBase): def setup_test(self): - pool.clear_managers() self._teardown_conns = [] def teardown_test(self): @@ -77,10 +76,6 @@ class PoolTestBase(fixtures.TestBase): if conn: conn.close() - @classmethod - def teardown_test_class(cls): - pool.clear_managers() - def _with_teardown(self, connection): self._teardown_conns.append(weakref.ref(connection)) return connection