From 3ad9995dfe7c14e8578afcc0ccdb2ee9d8c44db6 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 24 Oct 2022 18:23:26 -0500 Subject: [PATCH] Exec checks if tx is closed https://github.com/jackc/pgx/discussions/1350 --- tx.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tx.go b/tx.go index 24daf0f89..28a9af133 100644 --- a/tx.go +++ b/tx.go @@ -201,6 +201,10 @@ func (tx *dbTx) Rollback(ctx context.Context) error { // Exec delegates to the underlying *Conn func (tx *dbTx) Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error) { + if tx.closed { + return pgconn.CommandTag{}, ErrTxClosed + } + return tx.conn.Exec(ctx, sql, arguments...) }