vitessio/vitess · error
fillStringTemplate failed: %v
Error message
fillStringTemplate failed: %v
What it means
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.
Source
Thrown at go/vt/wrangler/schema.go:293
if resp != nil {
for _, e := range resp.Events {
logutil.LogEvent(wr.Logger(), e)
}
}
return err
}
// applySQLShard applies a given SQL change on a given tablet alias. It allows executing arbitrary
// SQL statements, but doesn't return any results, so it's only useful for SQL statements
// that would be run for their effects (e.g., CREATE).
// It works by applying the SQL statement on the shard's primary tablet with replication turned on.
// Thus it should be used only for changes that can be applied on a live instance without causing issues;
// it shouldn't be used for anything that will require a pivot.
// The SQL statement string is expected to have {{.DatabaseName}} in place of the actual db name.
func (wr *Wrangler) applySQLShard(ctx context.Context, tabletInfo *topo.TabletInfo, change string) error {
filledChange, err := fillStringTemplate(change, map[string]string{"DatabaseName": tabletInfo.DbName()})
if err != nil {
return fmt.Errorf("fillStringTemplate failed: %v", err)
}
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
// Need to make sure that replication is enabled since we're only applying the statement on primaries
_, err = wr.tmc.ApplySchema(ctx, tabletInfo.Tablet, &tmutils.SchemaChange{
SQL: filledChange,
Force: false,
AllowReplication: true,
SQLMode: vreplication.SQLMode,
})
return err
}
// fillStringTemplate returns the string template filled
func fillStringTemplate(tmpl string, vars any) (string, error) {
myTemplate := template.Must(template.New("").Parse(tmpl))
var data strings.Builder
if err := myTemplate.Execute(&data, vars); err != nil {View on GitHub (pinned to 01a25a7d17)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
if strings.Count(change, "{{") != strings.Count(change, "}}") {
return fmt.Errorf("malformed template in schema SQL: %s", change)
} Try / catch
err := wr.CopySchemaShard(ctx, src, dst, tables, excl, false)
if err != nil && strings.Contains(err.Error(), "fillStringTemplate failed") {
// inspect generated SQL for bad {{ }} sequences
} Prevention
- Quote or escape table/column names with template-like characters.
- Unit-test schema SQL generation with unusual identifiers.
When it happens
Trigger: The CREATE SQL string produced by tmutils.SchemaDefinitionToSQLStrings contains invalid template syntax (unbalanced {{ }} or bad directives), making text/template parsing fail inside fillStringTemplate.
Common situations: Table or column names containing template-like characters interfering with the {{.DatabaseName}} substitution; edge cases in schema-to-SQL generation for unusual identifiers.
Related errors
- failed to generate vtgate consul datacenter from template: %
- failed to parse vtgate FQDN template %s: %w
- failed to parse vtgate host address template %s: %w
- failed to generate vtctld consul datacenter from template: %
- failed to parse vtctld FQDN template %s: %w
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/7d58ee118d04f7aa.
Report an issue: GitHub.