From 697a4ddafab0ee1ca3780233055ad269dca13e5a Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Thu, 22 Oct 2026 07:32:16 +0200 Subject: [PATCH] Return25P02 for commands in aborted transactions --- datafusion-postgres/src/hooks/transactions.rs | 4 ++-- tests-integration/test_transactions.py | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/datafusion-postgres/src/hooks/transactions.rs b/datafusion-postgres/src/hooks/transactions.rs index 150424f1..97d3c7c0 100644 --- a/datafusion-postgres/src/hooks/transactions.rs +++ b/datafusion-postgres/src/hooks/transactions.rs @@ -43,7 +43,7 @@ impl QueryHook for TransactionStatementHook { return Some(Err(PgWireError::UserError(Box::new( pgwire::error::ErrorInfo::new( "ERROR".to_string(), - "25P01".to_string(), + "25P02".to_string(), "current transaction is aborted, commands ignored until end of transaction block".to_string(), ), )))); @@ -113,7 +113,7 @@ where Err(PgWireError::UserError(Box::new( pgwire::error::ErrorInfo::new( "ERROR".to_string(), - "25P01".to_string(), + "25P02".to_string(), "current transaction is aborted, commands ignored until end of transaction block".to_string(), ), ))) diff --git a/tests-integration/test_transactions.py b/tests-integration/test_transactions.py index 69e3ed2f..7df411c4 100755 --- a/tests-integration/test_transactions.py +++ b/tests-integration/test_transactions.py @@ -112,13 +112,15 @@ def test_failed_transaction_handling(conn): except Exception: print(" ✓ Invalid query failed as expected") - # Try to execute another query in failed transaction - try: - cur.execute('SELECT 1') - assert False, "Should be blocked in failed transaction" - except Exception as e: - assert "25P01" in str(e) or "aborted" in str(e).lower() - print(" ✓ Subsequent query blocked (error code 25P01)") + # Both transaction-hook rejection paths must use PostgreSQL's SQLSTATE. + for sql in ('SELECT 1', 'BEGIN'): + try: + cur.execute(sql) + except psycopg.Error as error: + assert error.sqlstate == '25P02', (sql, error.sqlstate) + else: + raise AssertionError(f"{sql} should be blocked in failed transaction") + print(" ✓ Queries and BEGIN blocked (error code 25P02)") # ROLLBACK should work cur.execute('ROLLBACK')