go-pg / pg

Golang ORM with focus on PostgreSQL features and performance
https://pg.uptrace.dev/
BSD 2-Clause "Simplified" License
5.65k stars 401 forks source link

r.db.RunInTransaction can not use r.db.ModelContext #1968

Closed chacoChao closed 1 year ago

chacoChao commented 1 year ago

Issue tracker is used for reporting bugs and discussing new features. Please use Discord or stackoverflow for supporting issues.

Expected Behavior

r.db.RunInTransaction can not use r.db.ModelContext

` r.db.RunInTransaction(ctx, func(tx pg.Tx) error { _, err := tx.ModelContext(ctx, (xxx)(nil)).WherePK("id = ?", xId).Delete()
_, err = tx.ModelContext(ctx, (*yyy)(nil)).Where("id = ?", yId)Delete()

// err="context canceled". the resason is can not get conn from db.pool //_, err = r.db.ModelContext(ctx, (*yyy)(nil)).WherePK("id = ?", clientId).Delete() `

Current Behavior

db.Model(book).Where().Delete() if table no rows. do delete() err = "context canceled"

image image image

Possible Solution

add condition rows empty return replace err

Steps to Reproduce

1. 2. 3. 4.

Context (Environment)

Detailed Description

Possible Implementation