1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-27 08:15:39 +02:00

[#1291] added condition to switch between the db pools in case of dry submit

This commit is contained in:
Gani Georgiev 2022-12-18 11:32:15 +02:00
parent 7d7d20744e
commit a43713ce14

View File

@ -675,9 +675,16 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
return err
}
// use the default app.Dao().ConcurrentDB() to prevent changing the transaction form.Dao
// and causing "transaction has already been committed or rolled back" error
dryDao := daos.New(form.app.Dao().ConcurrentDB())
var dryDao *daos.Dao
if form.dao.ConcurrentDB() == form.dao.NonconcurrentDB() {
// it is already in a transaction and therefore use the app concurrent db pool
// to prevent "transaction has already been committed or rolled back" error
dryDao = daos.New(form.app.Dao().ConcurrentDB())
} else {
// otherwise use the form noncurrent dao db pool
dryDao = daos.New(form.dao.NonconcurrentDB())
}
return dryDao.RunInTransaction(func(txDao *daos.Dao) error {
tx, ok := txDao.DB().(*dbx.Tx)
if !ok {
@ -685,11 +692,6 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
}
defer tx.Rollback()
txDao.BeforeCreateFunc = nil
txDao.AfterCreateFunc = nil
txDao.BeforeUpdateFunc = nil
txDao.AfterUpdateFunc = nil
if err := txDao.SaveRecord(form.record); err != nil {
return err
}