Skip to content

Conversation

@ptiurin
Copy link
Contributor

@ptiurin ptiurin commented Oct 29, 2025

This pull request introduces support for transaction management in the Firebolt database connection, including autocommit mode, explicit transaction control (begin, commit, rollback), and correct propagation of transaction state via HTTP headers. It also refactors how transaction-related parameters are handled and ensures thread safety for transaction operations. Additionally, some code cleanup and simplification around parameter parsing and header handling have been performed.

Design decisions:

  • autocommit attribute is read-only, setting it can only be done on connection creation.
  • BEGIN is a no-op when autocommit is ON.
  • BEGIN can't be run when autocommit is OFF - it's called automatically when a statement is executed. Users still can execute COMMIT/ROLLBACK or their methods.
  • FB 1.0 commit() and rollback() are no-op for backwards-compatibility.

Transaction Management Enhancements:

  • Added transaction state tracking (_transaction_id, _transaction_sequence_id) and autocommit mode to Connection and BaseConnection, with new methods for starting, committing, and rolling back transactions. The connection now manages transaction state based on HTTP response headers and propagates transaction parameters in outgoing requests.
  • Implemented thread-safe transaction operations using a trio.Lock to ensure only one transaction operation is in progress at a time.
  • Modified the connection close and context manager exit logic to automatically commit or rollback transactions as appropriate based on autocommit mode and transaction state.

Parameter and Header Handling Refactor:

  • Moved parsing of transaction-related parameters and headers from cursor to connection, centralizing transaction state management.
  • Refactored out parameter parsing utilities from base_cursor.py and reused them in connection and cursor logic.

Cursor and Query Execution Updates:

  • Updated the cursor to delegate query execution to the connection, allowing the connection to manage transaction parameters and state during query execution.
  • Removed now-unnecessary response header parsing logic from the cursor, as this is handled by the connection.

Constants and Utility Updates:

  • Introduced new constants for transaction parameter names and updated parameter lists to include transaction-related parameters.

These changes collectively enable robust transaction handling for async Firebolt connections and lay the groundwork for future enhancements around transactional consistency and error handling.

@ptiurin ptiurin changed the title feat: Add full transaction support feat(FIR-46457): Add full transaction support Oct 29, 2025
@sonarqubecloud
Copy link

@ptiurin ptiurin marked this pull request as ready for review October 30, 2025 11:04
@ptiurin ptiurin requested a review from a team as a code owner October 30, 2025 11:04
@ptiurin ptiurin merged commit d26aa71 into main Nov 3, 2025
8 checks passed
@ptiurin ptiurin deleted the transaction-implementation branch November 3, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants