diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-11-17 17:13:24 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-11-19 13:40:54 -0500 |
commit | 9b779611f9bafd6c0affafda9732cecdb8efa761 (patch) | |
tree | 41e98e407c5ca7872d3a97ce62214047c9c39bcf /test/engine/test_pool.py | |
parent | 7082e4c447c664af43a6576f5749c97a9951d7dd (diff) | |
download | sqlalchemy-9b779611f9bafd6c0affafda9732cecdb8efa761.tar.gz |
Support pool.connect() event firing before all else
Fixed regression where a connection pool event specified with a keyword,
most notably ``insert=True``, would be lost when the event were set up.
This would prevent startup events that need to fire before dialect-level
events from working correctly.
The internal mechanics of the engine connection routine has been altered
such that it's now guaranteed that a user-defined event handler for the
:meth:`_pool.PoolEvents.connect` handler, when established using
``insert=True``, will allow an event handler to run that is definitely
invoked **before** any dialect-specific initialization starts up, most
notably when it does things like detect default schema name.
Previously, this would occur in most cases but not unconditionally.
A new example is added to the schema documentation illustrating how to
establish the "default schema name" within an on-connect event
(upcoming as part of I882edd5bbe06ee5b4d0a9c148854a57b2bcd4741)
Addiional changes to support setting default schema name:
The Oracle dialect now uses
``select sys_context( 'userenv', 'current_schema' ) from dual`` to get
the default schema name, rather than ``SELECT USER FROM DUAL``, to
accommodate for changes to the session-local schema name under Oracle.
Added a read/write ``.autocommit`` attribute to the DBAPI-adaptation layer
for the asyncpg dialect. This so that when working with DBAPI-specific
schemes that need to use "autocommit" directly with the DBAPI connection,
the same ``.autocommit`` attribute which works with both psycopg2 as well
as pg8000 is available.
Fixes: #5716
Fixes: #5708
Change-Id: I7dce56b4345ffc720e25e2aaccb7e42bb29e5671
Diffstat (limited to 'test/engine/test_pool.py')
-rw-r--r-- | test/engine/test_pool.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index eb705da61..9ea3065b0 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -493,6 +493,26 @@ class PoolEventsTest(PoolTestBase): p.connect() eq_(canary, ["connect"]) + def test_connect_insert_event(self): + p = self._queuepool_fixture() + canary = [] + + def connect_one(*arg, **kw): + canary.append("connect_one") + + def connect_two(*arg, **kw): + canary.append("connect_two") + + def connect_three(*arg, **kw): + canary.append("connect_three") + + event.listen(p, "connect", connect_one) + event.listen(p, "connect", connect_two, insert=True) + event.listen(p, "connect", connect_three) + + p.connect() + eq_(canary, ["connect_two", "connect_one", "connect_three"]) + def test_connect_event_fires_subsequent(self): p, canary = self._connect_event_fixture() |