fix(11-05): sync single-statement and plain-transaction writes, type engine status errors

- pin the sync callbacks before gorm:commit_or_rollback_transaction: an
  After-only anchor is appended past the commit and lagoon's after-commit
  flush, so single-statement writes never synced
- give the gate and the document builder a clean session: Session with NewDB
  and a Context clones the write's statement, and a later WithContext queried
  through the written model's table
- typesense.StatusError carries method, path and status, never the body
- README: sync semantics, the three gates, delete on soft delete, and the
  SQL re-gate required of SearchIDs callers
This commit is contained in:
Jakub Zych
2026-09-30 13:05:10 +02:00
parent 3e1f3e6a1b
commit 9543e6508c
5 changed files with 63 additions and 9 deletions

View File

@@ -182,7 +182,7 @@ func (s *Service) syncOne(ctx context.Context, db *gorm.DB, p pending) (err erro
return nil
}
ctx = context.WithoutCancel(ctx)
sess := db.Session(&gorm.Session{NewDB: true, Context: ctx})
sess := cleanSession(db, ctx)
var (
skip bool
@@ -249,6 +249,16 @@ func (s *Service) syncOne(ctx context.Context, db *gorm.DB, p pending) (err erro
return nil
}
// cleanSession returns a handle on db's connection (the pool, or the open
// transaction) with an empty statement. db.Session with NewDB and a Context
// is not enough on a callback's handle: the Context makes it clone the
// write's statement (model, table, clauses), and a later WithContext on the
// result continues from that clone, so a gate query would run against the
// written model's table.
func cleanSession(db *gorm.DB, ctx context.Context) *gorm.DB {
return db.Session(&gorm.Session{NewDB: true, Context: ctx}).Clauses().Session(&gorm.Session{NewDB: true})
}
// inSavepoint runs fn on db. Inside a transaction fn runs in a savepoint,
// so a failed read (a table that does not exist yet, say) is rolled back
// to it and never aborts the caller's transaction.