{"record":{"id":"7d58ee118d04f7aa","repo":"vitessio/vitess","slug":"fillstringtemplate-failed-v","errorCode":null,"errorMessage":"fillStringTemplate failed: %v","messagePattern":"fillStringTemplate failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/schema.go","lineNumber":293,"sourceCode":"\tif resp != nil {\n\t\tfor _, e := range resp.Events {\n\t\t\tlogutil.LogEvent(wr.Logger(), e)\n\t\t}\n\t}\n\treturn err\n}\n\n// applySQLShard applies a given SQL change on a given tablet alias. It allows executing arbitrary\n// SQL statements, but doesn't return any results, so it's only useful for SQL statements\n// that would be run for their effects (e.g., CREATE).\n// It works by applying the SQL statement on the shard's primary tablet with replication turned on.\n// Thus it should be used only for changes that can be applied on a live instance without causing issues;\n// it shouldn't be used for anything that will require a pivot.\n// The SQL statement string is expected to have {{.DatabaseName}} in place of the actual db name.\nfunc (wr *Wrangler) applySQLShard(ctx context.Context, tabletInfo *topo.TabletInfo, change string) error {\n\tfilledChange, err := fillStringTemplate(change, map[string]string{\"DatabaseName\": tabletInfo.DbName()})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"fillStringTemplate failed: %v\", err)\n\t}\n\tctx, cancel := context.WithTimeout(ctx, 30*time.Second)\n\tdefer cancel()\n\t// Need to make sure that replication is enabled since we're only applying the statement on primaries\n\t_, err = wr.tmc.ApplySchema(ctx, tabletInfo.Tablet, &tmutils.SchemaChange{\n\t\tSQL:              filledChange,\n\t\tForce:            false,\n\t\tAllowReplication: true,\n\t\tSQLMode:          vreplication.SQLMode,\n\t})\n\treturn err\n}\n\n// fillStringTemplate returns the string template filled\nfunc fillStringTemplate(tmpl string, vars any) (string, error) {\n\tmyTemplate := template.Must(template.New(\"\").Parse(tmpl))\n\tvar data strings.Builder\n\tif err := myTemplate.Execute(&data, vars); err != nil {","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/schema.go#L275-L311","documentation":"applySQLShard fills the {{.DatabaseName}} placeholder in the generated SQL template (e.g. CREATE TABLE {{.DatabaseName}}.`...`) using fillStringTemplate before applying it to the destination primary. This error means the template substitution failed - almost always malformed Go template syntax in the schema-change SQL, not an environment issue.","triggerScenarios":"The CREATE SQL string produced by tmutils.SchemaDefinitionToSQLStrings contains invalid template syntax (unbalanced {{ }} or bad directives), making text/template parsing fail inside fillStringTemplate.","commonSituations":"Table or column names containing template-like characters interfering with the {{.DatabaseName}} substitution; edge cases in schema-to-SQL generation for unusual identifiers.","solutions":["Inspect the createSQL being applied for malformed {{ }} sequences.","Escape or rename identifiers that contain template delimiters.","Check the fillStringTemplate error text for the exact parse failure position."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if strings.Count(change, \"{{\") != strings.Count(change, \"}}\") {\n    return fmt.Errorf(\"malformed template in schema SQL: %s\", change)\n}","typeGuard":null,"tryCatchPattern":"err := wr.CopySchemaShard(ctx, src, dst, tables, excl, false)\nif err != nil && strings.Contains(err.Error(), \"fillStringTemplate failed\") {\n    // inspect generated SQL for bad {{ }} sequences\n}","preventionTips":["Quote or escape table/column names with template-like characters.","Unit-test schema SQL generation with unusual identifiers."],"tags":["go","template","schema"],"backgroundTag":"template-parse-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}