From 7738775417c9a83f77157f75207a454a88b2a9e7 Mon Sep 17 00:00:00 2001 From: georgysavva Date: Thu, 2 Apr 2020 15:30:55 +0300 Subject: [PATCH] Include context into stdlib.wrapTx{} in order to propagate it to the underlying pgx.Tx.Commit() and Rollback() methods. --- stdlib/sql.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/stdlib/sql.go b/stdlib/sql.go index 3dd92cbd..8ff3fd49 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -266,7 +266,7 @@ func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e return nil, err } - return wrapTx{tx: tx}, nil + return wrapTx{ctx: ctx, tx: tx}, nil } func (c *Conn) ExecContext(ctx context.Context, query string, argsV []driver.NamedValue) (driver.Result, error) { @@ -539,11 +539,14 @@ func namedValueToInterface(argsV []driver.NamedValue) []interface{} { return args } -type wrapTx struct{ tx pgx.Tx } +type wrapTx struct { + ctx context.Context + tx pgx.Tx +} -func (wtx wrapTx) Commit() error { return wtx.tx.Commit(context.Background()) } +func (wtx wrapTx) Commit() error { return wtx.tx.Commit(wtx.ctx) } -func (wtx wrapTx) Rollback() error { return wtx.tx.Rollback(context.Background()) } +func (wtx wrapTx) Rollback() error { return wtx.tx.Rollback(wtx.ctx) } type fakeTx struct{}