--- /dev/null
+.. change::
+ :tags: bug, orm, postgresql
+ :tickets: 4663
+
+ Added additional rollback during engine creation for postgresql
+ engines that prevents the first connection starting having an
+ implicit transaction created earlier than usual.
\ No newline at end of file
):
self._description_decoder = self.description_encoding = None
- self.do_rollback(connection.connection)
-
def on_connect(self):
"""return a callable which sets up a newly created DBAPI connection.
)
c._execution_options = util.immutabledict()
dialect.initialize(c)
+ dialect.do_rollback(c.connection)
event.listen(pool, "first_connect", first_connect, once=True)
"c %s NOT NULL" % expected,
)
+ def test_initial_transaction_state(self):
+ from psycopg2.extensions import STATUS_IN_TRANSACTION
+ engine = engines.testing_engine()
+ with engine.connect() as conn:
+ assert conn.connection.status != STATUS_IN_TRANSACTION
+
class AutocommitTextTest(test_execute.AutocommitTextTest):
__only_on__ = "postgresql"
eq_(conn._execution_options, {"autocommit": True})
conn.close()
+ def test_initialize_rollback(self):
+ """test a rollback happens during first connect"""
+ eng = create_engine(testing.db.url)
+ with patch.object(eng.dialect, "do_rollback") as do_rollback:
+ assert do_rollback.call_count == 0
+ connection = eng.connect()
+ assert do_rollback.call_count == 1
+ connection.close()
+
@testing.requires.ad_hoc_engines
def test_dialect_init_uses_options(self):
eng = create_engine(testing.db.url)