Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datafusion-postgres/src/hooks/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
))));
Expand Down Expand Up @@ -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(),
),
)))
Expand Down
16 changes: 9 additions & 7 deletions tests-integration/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading