Skip to content

refactor(table): centralize transaction metadata initialization checks #1431

Description

@fallintoplace

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions