{"record":{"id":"6a1f6b91a1457395","repo":"temporalio/temporal","slug":"unable-to-delete-custom-search-attributes-w","errorCode":null,"errorMessage":"unable to delete custom search attributes: %w","messagePattern":"unable to delete custom search attributes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/sql/sqlplugin/mysql/visibility.go","lineNumber":202,"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\t_, err = tx.NamedExecContext(ctx, templateDeleteCustomSearchAttributes, filter)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to delete custom search attributes: %w\", err)\n\t}\n\tresult, err = tx.NamedExecContext(ctx, templateDeleteWorkflowExecution_v8, filter)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to delete workflow execution: %w\", err)\n\t}\n\t_, err = tx.NamedExecContext(ctx, templateDeleteChasmSearchAttributes, filter)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to delete 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// SelectFromVisibility reads one or more rows from visibility table\nfunc (mdb *db) SelectFromVisibility(","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/sqlplugin/mysql/visibility.go#L184-L220","documentation":"Returned when the DELETE against templateDeleteCustomSearchAttributes fails inside the DeleteFromVisibility transaction. The transaction is rolled back by the deferred handler, so no partial deletion occurs. The wrapped driver error carries the real cause (constraint violation, connection failure, syntax error, etc.).","triggerScenarios":"Calling DeleteFromVisibility (public API of the MySQL visibility store) when the named exec on the custom search attributes table errors — missing table/schema mismatch, connection loss, or lock wait timeout on the executions_visibility row.","commonSituations":"Visibility schema not migrated (custom search attributes table missing after upgrade); deadlocks/lock timeouts from concurrent deletes; DB failover mid-transaction.","solutions":["Inspect the wrapped cause with errors.Unwrap / %v of the error to see the MySQL errno.","Run the latest visibility schema migration so all tables (including CHASM search attributes) exist.","Retry the delete; transient lock timeouts and deadlocks resolve on retry.","Check for concurrent deletes of the same WorkflowExecution (RunID) causing lock contention."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Go: ensure schema is current before operations\nvar exists int\nerr := db.QueryRow(\"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?\", schemaName, \"custom_search_attributes\").Scan(&exists)\nif err != nil || exists == 0 { /* run migrations */ }","typeGuard":null,"tryCatchPattern":"// Go\nerr := store.DeleteFromVisibility(ctx, req)\nif err != nil {\n    var retryable bool\n    if isDeadlockOrTimeout(err) { retryable = true }\n    return wrapAndMaybeRetry(err, retryable)\n}","preventionTips":["Keep visibility schema migrations applied before deploying new server versions","Use retry policies for deadlock/lock-timeout MySQL errors (1205, 1213)","Avoid concurrent deletes of the same RunID","Grant the DB user full DML privileges on all visibility tables"],"tags":["mysql","database","delete","transaction","schema-migration"],"backgroundTag":"sql-query-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}