{"record":{"id":"e84cad70bdd5b959","repo":"temporalio/temporal","slug":"unable-to-insert-workflow-execution-w","errorCode":null,"errorMessage":"unable to insert workflow execution: %w","messagePattern":"unable to insert workflow execution: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/sql/sqlplugin/mysql/visibility.go","lineNumber":114,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttx, err := db.BeginTxx(ctx, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer func() {\n\t\terr := tx.Rollback()\n\t\t// If the error is sql.ErrTxDone, it means the transaction already closed, so ignore error.\n\t\tif err != nil && !errors.Is(err, sql.ErrTxDone) {\n\t\t\t// Transaction rollback error should never happen, unless db connection was lost.\n\t\t\tretError = fmt.Errorf(\"transaction rollback failed: %w\", retError)\n\t\t}\n\t}()\n\tresult, err = tx.NamedExecContext(ctx, templateInsertWorkflowExecution, finalRow)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to insert workflow execution: %w\", err)\n\t}\n\t_, err = tx.NamedExecContext(ctx, templateInsertCustomSearchAttributes, finalRow)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to insert custom search attributes: %w\", err)\n\t}\n\t_, err = tx.NamedExecContext(ctx, templateInsertChasmSearchAttributes, finalRow)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to insert chasm search attributes: %w\", err)\n\t}\n\terr = tx.Commit()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn result, nil\n}\n\n// ReplaceIntoVisibility replaces an existing row if it exist or creates a new row in visibility table\nfunc (mdb *db) ReplaceIntoVisibility(","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/sqlplugin/mysql/visibility.go#L96-L132","documentation":"InsertIntoVisibility executes a three-statement transaction: insert into the executions visibility table, then custom search attributes, then CHASM search attributes. This error wraps the failure of the first statement (templateInsertWorkflowExecution) via NamedExecContext and aborts the transaction. Typical causes are MySQL constraint violations, schema drift, or connection errors.","triggerScenarios":"Calling InsertIntoVisibility where the INSERT into the visibility executions table fails: duplicate row handling rejected by schema, column mismatch from an out-of-date schema (visibility schema version), too-long column values (e.g. WorkflowTypeName/Identifier over column size), or a lost connection.","commonSituations":"Visibility store schema not migrated after upgrading Temporal (missing new columns in visibility_workflow_executions); SQL mode strictness rejecting oversized data; connection issues to the visibility database.","solutions":["Read the wrapped MySQL error in the message to identify the exact cause (dup key, data too long, unknown column).","Run the visibility schema migrations (temporal-sql-tool / schema setup) to ensure the visibility store matches the server's expected schema version.","Check row values: truncated/oversized SearchAttribute or workflow name data against column definitions.","Verify the visibility DB connection is healthy and using the correct database name in config.","If it is a duplicate-key style failure, confirm the caller semantics — for replace behavior use ReplaceIntoVisibility instead."],"exampleFix":"// before: schema missing columns added in newer version\n// visibility_workflow_executions lacks new SA columns\n\n// after: apply the visibility schema update\ntemporal-sql-tool -plugin mysql -ep $DB_HOST -u $DB_USER -p $DB_PWD update-schema -d temporal_visibility","handlingStrategy":"try-catch","validationCode":"// Go: preflight schema version check\nvar v string\nif err := visibilityDB.GetContext(ctx, &v, \"SELECT version_ref FROM schema_version\"); err != nil || v < requiredVersion {\n    logger.Fatal(\"visibility schema out of date; run update-schema\")\n}","typeGuard":null,"tryCatchPattern":"if err := db.InsertIntoVisibility(ctx, row); err != nil {\n    if strings.Contains(err.Error(), \"unable to insert workflow execution\") {\n        logger.Error(\"visibility insert failed; check wrapped MySQL error/schema\", tag.Error(err))\n        return convertPersistenceErr(err)\n    }\n    return err\n}","preventionTips":["Always run visibility schema update-schema after upgrading the Temporal server.","Pin SQL mode and validate column sizes for run IDs, workflow types, and search attributes.","Add persistence-layer error metrics/alerts to catch insert failures early.","Use ReplaceIntoVisibility semantics only when the caller truly intends replace behavior."],"tags":["mysql","visibility","insert","schema"],"backgroundTag":"sql-insert-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}