microsoft / microsoft/mssql-python

Connection keeps open transaction (open_transaction_count) after connection.commit - works as intended?

Geschlossen
#754 4 Kommentare 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

@sumitmsft arbeitet bereits daran.

Seit 09.9.2026.

area: performance bug inADO regression triage done under development
Vorherrschende Sprache
Python
Sterne
473
Forks
60
Ø Merge
2 T. 11 Std.
Gemergte PRs (30 T.)
36

Beschreibung

Hello,

when using mssql-python we observed that it does not seem to close/commit all transactions.
For example with this script:

with mssql_python.connect(conn_string) as conn:
  with conn.cursor() as cursor:
    cursor.execute("SELECT * FROM People")

print("wait here with debugger")

Before the application exits we see open transactions with this:

SELECT 
  s.session_id,
  s.login_time,
  s.host_name,
  s.program_name,
  s.login_name,
  s.last_request_end_time,
  c.most_recent_sql_handle,
  s.open_transaction_count,
  r.*
FROM sys.dm_exec_sessions s
LEFT JOIN sys.dm_exec_requests r
  ON r.session_id = s.session_id
LEFT JOIN sys.dm_exec_connections c
  ON c.session_id = s.session_id
WHERE s.open_transaction_count > 0

Is this intended behavior? The opened transaction does not seem to block any resources.

When doing a manual commit cursor.execute("IF @@TRANCOUNT > 0 COMMIT TRANSACTION") the transactions are closed properly before the application exits.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.