bytebase/bytebase · error

naming_payload is required for this rule

Error message

naming_payload is required for this rule

What it means

The PostgreSQL primary key naming convention advisor requires a rule payload of type naming (with a Format field, typically a template like "{database}_{table}_pk") to validate primary key names. The Check function calls Rule.GetNamingPayload() and throws this error when the attached rule has no naming payload configured. It is a configuration guard, not a runtime failure of SQL analysis itself.

Source

Thrown at backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go:39

func init() {
	advisor.Register(storepb.Engine_POSTGRES, storepb.SQLReviewRule_NAMING_INDEX_PK, &NamingPKConventionAdvisor{})
}

// NamingPKConventionAdvisor is the advisor checking for primary key naming convention.
type NamingPKConventionAdvisor struct {
}

// Check checks for primary key naming convention.
func (*NamingPKConventionAdvisor) Check(_ context.Context, checkCtx advisor.Context) ([]*storepb.Advice, error) {
	level, err := advisor.NewStatusBySQLReviewRuleLevel(checkCtx.Rule.Level)
	if err != nil {
		return nil, err
	}

	namingPayload := checkCtx.Rule.GetNamingPayload()
	if namingPayload == nil {
		return nil, errors.New("naming_payload is required for this rule")
	}

	format := namingPayload.Format
	templateList, _ := advisor.ParseTemplateTokens(format)

	for _, key := range templateList {
		if _, ok := advisor.TemplateNamingTokens[checkCtx.Rule.Type][key]; !ok {
			return nil, errors.Errorf("invalid template %s for rule %s", key, checkCtx.Rule.Type)
		}
	}

	maxLength := int(namingPayload.MaxLength)
	if maxLength == 0 {
		maxLength = advisor.DefaultNameLengthLimit
	}

	rule := &namingPKConventionRule{
		OmniBaseRule: OmniBaseRule{

View on GitHub (pinned to 1870550677)

Solutions

  1. Set the rule's naming payload with a valid format template, e.g. {"format": "{database}_{table}_pk"} on the SQLReviewRule payload.
  2. Verify the payload is stored in the naming payload field of the rule proto (protojson camelCase "namingPayload") so GetNamingPayload() resolves it.
  3. Re-save the SQL review policy rule through the API/UI and confirm the format field is non-empty before running the check.

Example fix

// before
rule := &storepb.SQLReviewRule{Type: storepb.SQLReviewRule_NAMING_PRIMARY_KEY_CONVENTION}
// after
rule := &storepb.SQLReviewRule{
  Type: storepb.SQLReviewRule_NAMING_PRIMARY_KEY_CONVENTION,
  Payload: mustMarshal(&storepb.SQLReviewRulePayload_NamingPayloadConfig{
    NamingPayloadConfig: &storepb.NamingRulePayload{Format: "{database}_{table}_pk"},
  }),
}
Defensive patterns

Strategy: validation

Validate before calling

if rule.GetNamingPayload() == nil || rule.GetNamingPayload().Format == "" {
  return fmt.Errorf("rule %s requires a naming payload with a format", rule.Type)
}
// proceed to advisor.Check(ctx)

Prevention

When it happens

Trigger: Calling advisor.Check (pg/advisor) with a CheckContext whose Rule is the primary key naming convention rule but whose payload is nil — e.g. the rule was created in the policy without setting the naming payload, or the payload was stored under the wrong oneof field so GetNamingPayload() returns nil.

Common situations: SQL review policies configured via API/UI where the naming format was never filled in; policies imported from another project with stripped payloads; programmatic rule construction that sets Rule.Type but forgets Rule.Payload.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/a762b21b6a724b24. Report an issue: GitHub.