Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: dfd36ebc by Mark Sapiro at 2018-02-25T08:49:37-08:00 Refactor mailman/database/base.py change now that pool_pre_ping=True can be passed to sqlalchemy.create_engine. - - - - - 483de455 by Mark Sapiro at 2018-02-26T00:32:21+00:00 Merge branch 'database' into 'master' Refactor mailman/database/base.py change. See merge request mailman/mailman!361 - - - - - 2 changed files: - src/mailman/database/base.py - src/mailman/docs/NEWS.rst Changes: ===================================== src/mailman/database/base.py ===================================== --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -23,7 +23,7 @@ from mailman.config import config from mailman.interfaces.database import IDatabase from mailman.utilities.string import expand from public import public -from sqlalchemy import create_engine, event, exc, select +from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from zope.interface import implementer @@ -103,47 +103,8 @@ class SABaseDatabase: # engines, and yes, we could have chmod'd the file after the fact, but # half dozen and all... self.url = url - self.engine = create_engine(url, isolation_level='READ UNCOMMITTED') + self.engine = create_engine( + url, isolation_level='READ UNCOMMITTED', pool_pre_ping=True) session = sessionmaker(bind=self.engine) self.store = session() self.store.commit() - # This is from the Dealing with Disconnects section at - # <http://docs.sqlalchemy.org/en/latest/core/pooling.html>. It - # establishes connection pinging to deal with lost connections due to - # database server restarts or other outside events. - # - # XXX This can all be removed once SQLAlchemy 1.2 is released, and we - # pass `pool_pre_ping=True` to create_engine(). - @event.listens_for(self.engine, 'engine_connect') # noqa: E306 - def ping_connection(connection, branch): # pragma: nocover - if branch: - # "branch" refers to a sub-connection of a connection; - # we don't want to bother pinging on these. - return - # Turn off "close with result". This flag is only used with - # "connectionless" execution, otherwise will be False in any case. - old_scwr = connection.should_close_with_result - connection.should_close_with_result = False - try: - # Run a SELECT 1. Use a core select() so that the SELECT of a - # scalar value without a table is appropriately formatted for - # the backend. - connection.scalar(select([1])) - except exc.DBAPIError as error: - # Catch SQLAlchemy's DBAPIError, which is a wrapper for the - # DBAPI's exception. It includes a .connection_invalidated - # attribute which specifies if this connection is a - # "disconnect" condition, which is based on inspection of the - # original exception by the dialect in use. - if error.connection_invalidated: - # Run the same SELECT again - the connection will - # re-validate itself and establish a new connection. The - # disconnect detection here also causes the whole - # connection pool to be invalidated so that all stale - # connections are discarded. - connection.scalar(select([1])) - else: - raise - finally: - # Restore "close with result". - connection.should_close_with_result = old_scwr ===================================== src/mailman/docs/NEWS.rst ===================================== --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -78,6 +78,11 @@ Configuration * Mailman now also searches at ``/etc/mailman3/mailman.cfg`` for the configuration file. +Database +-------- +* The fix for #313 which ported an upstream SQLAlchemy fix to Mailman + has been refactored now that SQLAlchemy 1.2 has been released. + Interfaces ---------- * Broaden the semantics for ``IListManager.get()``. This API now accepts View it on GitLab: https://gitlab.com/mailman/mailman/compare/2efaf34ae4bf1a66cecea65f094affa1dfb316bb...483de45545ed87f0559a46bd008610f6fa19dfd2 --- View it on GitLab: https://gitlab.com/mailman/mailman/compare/2efaf34ae4bf1a66cecea65f094affa1dfb316bb...483de45545ed87f0559a46bd008610f6fa19dfd2 You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org