{"record":{"id":"a762b21b6a724b24","repo":"bytebase/bytebase","slug":"naming-payload-is-required-for-this-rule-a762b2","errorCode":null,"errorMessage":"naming_payload is required for this rule","messagePattern":"naming_payload is required for this rule","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go","lineNumber":39,"sourceCode":"\nfunc init() {\n\tadvisor.Register(storepb.Engine_POSTGRES, storepb.SQLReviewRule_NAMING_INDEX_PK, &NamingPKConventionAdvisor{})\n}\n\n// NamingPKConventionAdvisor is the advisor checking for primary key naming convention.\ntype NamingPKConventionAdvisor struct {\n}\n\n// Check checks for primary key naming convention.\nfunc (*NamingPKConventionAdvisor) Check(_ context.Context, checkCtx advisor.Context) ([]*storepb.Advice, error) {\n\tlevel, err := advisor.NewStatusBySQLReviewRuleLevel(checkCtx.Rule.Level)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tnamingPayload := checkCtx.Rule.GetNamingPayload()\n\tif namingPayload == nil {\n\t\treturn nil, errors.New(\"naming_payload is required for this rule\")\n\t}\n\n\tformat := namingPayload.Format\n\ttemplateList, _ := advisor.ParseTemplateTokens(format)\n\n\tfor _, key := range templateList {\n\t\tif _, ok := advisor.TemplateNamingTokens[checkCtx.Rule.Type][key]; !ok {\n\t\t\treturn nil, errors.Errorf(\"invalid template %s for rule %s\", key, checkCtx.Rule.Type)\n\t\t}\n\t}\n\n\tmaxLength := int(namingPayload.MaxLength)\n\tif maxLength == 0 {\n\t\tmaxLength = advisor.DefaultNameLengthLimit\n\t}\n\n\trule := &namingPKConventionRule{\n\t\tOmniBaseRule: OmniBaseRule{","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the rule's naming payload with a valid format template, e.g. {\"format\": \"{database}_{table}_pk\"} on the SQLReviewRule payload.","Verify the payload is stored in the naming payload field of the rule proto (protojson camelCase \"namingPayload\") so GetNamingPayload() resolves it.","Re-save the SQL review policy rule through the API/UI and confirm the format field is non-empty before running the check."],"exampleFix":"// before\nrule := &storepb.SQLReviewRule{Type: storepb.SQLReviewRule_NAMING_PRIMARY_KEY_CONVENTION}\n// after\nrule := &storepb.SQLReviewRule{\n  Type: storepb.SQLReviewRule_NAMING_PRIMARY_KEY_CONVENTION,\n  Payload: mustMarshal(&storepb.SQLReviewRulePayload_NamingPayloadConfig{\n    NamingPayloadConfig: &storepb.NamingRulePayload{Format: \"{database}_{table}_pk\"},\n  }),\n}","handlingStrategy":"validation","validationCode":"if rule.GetNamingPayload() == nil || rule.GetNamingPayload().Format == \"\" {\n  return fmt.Errorf(\"rule %s requires a naming payload with a format\", rule.Type)\n}\n// proceed to advisor.Check(ctx)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always validate rule payloads (non-nil, format non-empty) before registering them in a SQL review policy.","Use typed constructors for policy rules that force callers to supply the payload.","Add a policy lint/CI check that walks all enabled rules and asserts each has the payload its type requires."],"tags":["config","sql-review","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}