{"record":{"id":"096948d027f66841","repo":"vitessio/vitess","slug":"duplicate-session-variable-name-q","errorCode":null,"errorMessage":"duplicate session variable name: %q","messagePattern":"duplicate session variable name: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schema/ddl_strategy.go","lineNumber":231,"sourceCode":"\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}\n\treturn nil\n}\n\n// SetStatement returns a SET statement for the variable.\nfunc (variable SessionVariable) SetStatement() (string, error) {\n\tif err := ValidateSessionVariable(variable); err != nil {\n\t\treturn \"\", err\n\t}\n\t// A connection default or an earlier assignment may enable\n\t// NO_BACKSLASH_ESCAPES.\n\t// In that mode, encoding O'Reilly as 'O\\'Reilly' closes the string after\n\t// the backslash; on a multi-statement DBA connection, a crafted suffix could\n\t// then be parsed as another statement. A hex literal is parsed safely\n\t// regardless of the active sql_mode.\n\treturn fmt.Sprintf(\"set @@session.%s=X'%x'\", variable.Name, variable.Value), nil","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schema/ddl_strategy.go#L213-L249","documentation":"ValidateSessionVariables rejects case-insensitive duplicate session variable names in the ordered list parsed from repeated --session-variable options. Setting the same variable twice is ambiguous, so the second occurrence fails validation. Comparison is via strings.ToLower normalization.","triggerScenarios":"Passing two --session-variable flags with the same name in any case, e.g. --session-variable wait_timeout=100 --session-variable WAIT_TIMEOUT=200, which reaches this error through DDLStrategySetting.SessionVariables().","commonSituations":"Scripted command builders that append flags without de-duplicating; configuration templates merging user defaults with overrides; shell wrappers accumulating flags across layers.","solutions":["Remove or merge duplicate --session-variable flags so each name appears once.","De-duplicate case-insensitively in whatever code builds the flag list.","If override semantics are needed, apply the last value yourself before constructing the strategy string."],"exampleFix":"// before\nstrategy := \"online --session-variable wait_timeout=100 --session-variable wait_timeout=200\"\n// after\nstrategy := \"online --session-variable wait_timeout=200\"","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, v := range vars {\n    k := strings.ToLower(v.Name)\n    if seen[k] { /* dedupe: keep last */ }\n    seen[k] = true\n}","typeGuard":null,"tryCatchPattern":"if err := schema.ValidateSessionVariables(vars); err != nil {\n    return fmt.Errorf(\"invalid session variables: %w\", err)\n}","preventionTips":["De-duplicate flags case-insensitively in flag-building code.","Prefer applying overrides in a map before serializing to flags.","Test templates that merge defaults with user overrides."],"tags":["ddl","online-schema-change","validation"],"backgroundTag":"duplicate-session-variable","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}