Context
PR #1388 added initialization error handling to transactions. It also exposed a maintainability problem: many transaction entry points access t.meta directly, and each one has to remember to call ensureInitialized() first. The original review missed UpdateSchema and UpdateSpec, which is exactly the kind of omission this issue is about.
Proposal
Add one internal accessor for transaction metadata and use it anywhere transaction code needs the metadata builder:
func (t *Transaction) txnMeta() (*MetadataBuilder, error) {
if err := t.ensureInitialized(); err != nil {
return nil, err
}
return t.meta, nil
}
Callers should obtain the builder through this accessor before reading or mutating transaction metadata:
meta, err := t.txnMeta()
if err != nil {
return err
}
currentSchema := meta.CurrentSchema()
The nil transaction case should return a normal error instead of falling through to a nil dereference.
Scope
- Audit transaction methods and replace direct metadata access with
txnMeta().
- Update
NewUpdateSpec and NewUpdateSchema to use the same path.
- Keep the existing public transaction constructors and their error behavior unchanged.
- Add regression coverage for nil transactions, broken transaction initialization, and representative transaction entry points.
Acceptance criteria
- Metadata access from transaction entry points consistently passes through the checked accessor.
- Broken or nil transactions return an error instead of panicking.
- Existing valid transaction behavior is unchanged.
- The regression tests cover the paths that previously missed
ensureInitialized().
Related: #1388
Context
PR #1388 added initialization error handling to transactions. It also exposed a maintainability problem: many transaction entry points access
t.metadirectly, and each one has to remember to callensureInitialized()first. The original review missedUpdateSchemaandUpdateSpec, which is exactly the kind of omission this issue is about.Proposal
Add one internal accessor for transaction metadata and use it anywhere transaction code needs the metadata builder:
Callers should obtain the builder through this accessor before reading or mutating transaction metadata:
The nil transaction case should return a normal error instead of falling through to a nil dereference.
Scope
txnMeta().NewUpdateSpecandNewUpdateSchemato use the same path.Acceptance criteria
ensureInitialized().Related: #1388