{"record":{"id":"baa8220f6ab32efe","repo":"temporalio/temporal","slug":"unable-to-upsert-chasm-search-attributes-w","errorCode":null,"errorMessage":"unable to upsert chasm search attributes: %w","messagePattern":"unable to upsert chasm search attributes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/sql/sqlplugin/mysql/visibility.go","lineNumber":166,"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, templateUpsertWorkflowExecution, finalRow)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to upsert workflow execution: %w\", err)\n\t}\n\t_, err = tx.NamedExecContext(ctx, templateUpsertCustomSearchAttributes, finalRow)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to upsert custom search attributes: %w\", err)\n\t}\n\t_, err = tx.NamedExecContext(ctx, templateUpsertChasmSearchAttributes, finalRow)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to upsert 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// DeleteFromVisibility deletes a row from visibility table if it exist\nfunc (mdb *db) DeleteFromVisibility(\n\tctx context.Context,\n\tfilter sqlplugin.VisibilityDeleteFilter,\n) (result sql.Result, retError error) {\n\tdefer func() {\n\t\tretError = mdb.handle.ConvertError(retError)\n\t}()\n\tdb, err := mdb.handle.DB()\n\tif err != nil {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/sqlplugin/mysql/visibility.go#L148-L184","documentation":"The final statement in the ReplaceIntoVisibility transaction — the upsert into the CHASM search attributes table — failed, wrapped as 'unable to upsert chasm search attributes'. The transaction rolls back so no partial visibility state is written. Like the insert counterpart, this most often means the visibility store schema is missing the CHASM table introduced with CHASM visibility support.","triggerScenarios":"ReplaceIntoVisibility: templateUpsertChasmSearchAttributes NamedExecContext fails — visibility_chasm_search_attributes table absent (old schema), constraint violation on chasm fields, or connection loss before commit.","commonSituations":"Server upgraded to a CHASM-enabled release without visibility schema migration; stale visibility DB in test/staging environments; conflicting chasm attribute rows during upsert.","solutions":["Unwrap the cause: 'Table temporal_visibility.visibility_chasm_search_attributes doesn't exist' means run schema migrations.","Apply the latest visibility schema: temporal-sql-tool update-schema -d temporal_visibility.","Verify the deployed server binary and visibility schema version are compatible.","If constraint-related, inspect the VisibilityRow chasm fields for consistency.","Retry after confirming DB connectivity if the cause is a connection error."],"exampleFix":"// before: old schema, CHASM table missing\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.ReplaceIntoVisibility(ctx, row); err != nil {\n    if strings.Contains(err.Error(), \"unable to upsert chasm search attributes\") {\n        logger.Error(\"chasm SA upsert failed; likely visibility schema drift\", tag.Error(err))\n        return convertPersistenceErr(err)\n    }\n    return err\n}","preventionTips":["Run visibility schema update-schema as part of every deployment/upgrade runbook.","Include the CHASM table existence check in startup readiness checks.","Keep environments (dev/staging/prod) on identical visibility schema versions."],"tags":["mysql","visibility","chasm","upsert","schema"],"backgroundTag":"sql-upsert-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}