{"record":{"id":"c90110886833ec83","repo":"vitessio/vitess","slug":"session-variable-q-is-not-allowed","errorCode":null,"errorMessage":"session variable %q is not allowed","messagePattern":"session variable %q is not allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schema/ddl_strategy.go","lineNumber":216,"sourceCode":"\n// IsSingletonTable checks if strategy options include --singleton-table\nfunc (setting *DDLStrategySetting) IsSingletonTable() bool {\n\treturn setting.hasFlag(singletonTableFlag)\n}\n\n// IsAllowZeroInDateFlag checks if strategy options include --allow-zero-in-date\nfunc (setting *DDLStrategySetting) IsAllowZeroInDateFlag() bool {\n\treturn setting.hasFlag(allowZeroInDateFlag)\n}\n\n// ValidateSessionVariable ensures a variable name is safe to interpolate as a\n// MySQL system variable identifier.\nfunc ValidateSessionVariable(variable SessionVariable) error {\n\tif !sessionVariableNameRegexp.MatchString(variable.Name) {\n\t\treturn fmt.Errorf(\"invalid session variable name: %q\", variable.Name)\n\t}\n\tif _, ok := deniedSessionVariables[strings.ToLower(variable.Name)]; ok {\n\t\treturn fmt.Errorf(\"session variable %q is not allowed\", variable.Name)\n\t}\n\treturn nil\n}\n\n// ValidateSessionVariables validates variable names and rejects\n// case-insensitive duplicates.\nfunc ValidateSessionVariables(variables []SessionVariable) error {\n\tseen := map[string]struct{}{}\n\tfor _, variable := range variables {\n\t\tif err := ValidateSessionVariable(variable); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tnormalizedName := strings.ToLower(variable.Name)\n\t\tif _, ok := seen[normalizedName]; ok {\n\t\t\treturn fmt.Errorf(\"duplicate session variable name: %q\", variable.Name)\n\t\t}\n\t\tseen[normalizedName] = struct{}{}\n\t}","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schema/ddl_strategy.go#L198-L234","documentation":"ValidateSessionVariable checks a DDL strategy session variable name against a regexp and then against a denylist (deniedSessionVariables). This error means the variable name is syntactically valid but is explicitly forbidden (e.g. variables Vitess must control itself during online schema changes, like foreign_key_checks or sql_log_bin). The variable's value is irrelevant; the name itself is rejected case-insensitively.","triggerScenarios":"Calling ParseDDLStrategy or SessionVariables() with a --session-variable option whose name is in the denied set, e.g. --ddl-strategy=\"online --session-variable foreign_key_checks=0\". Validation runs via ValidateSessionVariables -> ValidateSessionVariable.","commonSituations":"Users porting plain-MySQL ALTER workflows to Vitess online DDL and disabling server-controlled settings (foreign_key_checks, unique_checks, sql_log_bin) that Vitess manages itself; copy-pasted MySQL client commands including these variables.","solutions":["Remove the denied variable from the --session-variable list in the DDL strategy.","Check the deniedSessionVariables map in go/vt/schema/ddl_strategy.go to see which names are forbidden.","Use an allowed alternative: e.g. rely on the DDL strategy's own options instead of disabling foreign_key_checks manually."],"exampleFix":"// before\ndl := schema.ParseDDLStrategy(\"online --session-variable foreign_key_checks=0\")\n// after\ndl := schema.ParseDDLStrategy(\"online\")","handlingStrategy":"validation","validationCode":"for _, v := range variables {\n    if schema.ValidateSessionVariable(schema.SessionVariable{Name: v.Name, Value: v.Value}) != nil {\n        // drop or fix this variable before building the strategy\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := schema.ValidateSessionVariables(vars); err != nil {\n    return fmt.Errorf(\"rejecting DDL strategy: %w\", err)\n}","preventionTips":["Keep a copy of the denylist in tooling that builds --session-variable flags.","Never add variables Vitess owns (foreign_key_checks, sql_log_bin, unique_checks).","Unit-test any code that composes DDL strategy strings."],"tags":["ddl","online-schema-change","validation"],"backgroundTag":"denied-session-variable","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}