connectionless execution causes TLConnection to stay open incorreclty in certain scenarios

Issue #3780 new
jbeluch created an issue

Somewhat related to https://bitbucket.org/zzzeek/sqlalchemy/issues/3779/threadlocal-engine-sometimes-doesnt.

All calls to .contextual_connect() return the same TLConnection object, however sometimes the caller wants a Connection with the should_close_with_result attr set to True on the connection (connectionless execution via engine.execute). So, if the TLConnection is initially created with close_with_result=False, then calls to engine.execute() will increment the __open_count counter while never calling .close() to decrement it.

Failing test:

    def test_tlbind_close_conn(self):
         e = create_engine(testing.db.url, strategy='threadlocal')
         conn = e.contextual_connect()
         e.execute('select 1').fetchall()
         conn.close()
         assert conn.closed

Comments (3)

  1. Log in to comment