{"record":{"id":"9ef7be7be430c349","repo":"temporalio/temporal","slug":"unable-to-insert-chasm-search-attributes-w","errorCode":null,"errorMessage":"unable to insert chasm search attributes: %w","messagePattern":"unable to insert chasm search attributes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/sql/sqlplugin/mysql/visibility.go","lineNumber":122,"sourceCode":"\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(\n\tctx context.Context,\n\trow *sqlplugin.VisibilityRow,\n) (result sql.Result, retError error) {\n\tdefer func() {\n\t\tretError = mdb.handle.ConvertError(retError)\n\t}()\n\tfinalRow := mdb.prepareRowForDB(row)\n\tdb, err := mdb.handle.DB()","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/sqlplugin/mysql/visibility.go#L104-L140","documentation":"The third statement of the InsertIntoVisibility transaction — inserting into the CHASM search attributes table (templateInsertChasmSearchAttributes) — failed. The transaction is rolled back and the error wrapped as 'unable to insert chasm search attributes'. CHASM visibility is a newer feature, so this most commonly fires when the visibility store schema predates the CHASM table.","triggerScenarios":"InsertIntoVisibility: templateInsertChasmSearchAttributes NamedExecContext fails — visibility_chasm_search_attributes table missing (old schema), constraint violation on the row, or connection loss mid-transaction.","commonSituations":"Upgrading to a Temporal version with CHASM visibility support without updating the visibility schema; misconfigured visibility database pointing at a stale schema; duplicate/inconsistent chasm attributes in the row struct.","solutions":["Check the wrapped cause: 'Table ... doesn't exist' means apply the latest visibility schema migrations.","Run temporal-sql-tool update-schema against the temporal_visibility database.","Verify the visibility store type/version supports CHASM (MySQL >= supported version, schema >= required release).","If the wrapped error is constraint/dup-key related, inspect the VisibilityRow chasm fields for consistency with the execution row.","Confirm connectivity to the visibility DB if the cause is a driver/connection error."],"exampleFix":"// before: visibility schema older than server binary\n// after\ntemporal-sql-tool -plugin mysql -ep $DB_HOST -u $DB_USER -p $DB_PWD update-schema -d temporal_visibility","handlingStrategy":"validation","validationCode":"// Go: verify CHASM table exists at startup\nvar cnt int\nif err := visDB.GetContext(ctx, &cnt,\n    \"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'visibility_chasm_search_attributes'\"); err != nil || cnt == 0 {\n    logger.Fatal(\"visibility schema missing CHASM tables; run update-schema\")\n}","typeGuard":null,"tryCatchPattern":"if err := db.InsertIntoVisibility(ctx, row); err != nil {\n    if strings.Contains(err.Error(), \"unable to insert chasm search attributes\") {\n        logger.Error(\"chasm SA insert failed; likely visibility schema drift\", tag.Error(err))\n        return convertPersistenceErr(err)\n    }\n    return err\n}","preventionTips":["Apply visibility schema migrations whenever the server binary is upgraded.","Keep test/staging visibility DBs on the same schema version as production.","Verify the DB user has INSERT privileges on all three visibility tables."],"tags":["mysql","visibility","chasm","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"}