{"record":{"id":"455098f24cdb3016","repo":"temporalio/temporal","slug":"v-rows-were-affected-instead-of-1","errorCode":null,"errorMessage":"%v rows were affected instead of 1","messagePattern":"(.+?) rows were affected instead of 1","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/sql/task_queues.go","lineNumber":122,"sourceCode":"\t\t); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tresult, err := tx.UpdateTaskQueues(ctx, &sqlplugin.TaskQueuesRow{\n\t\t\tRangeHash:    tqHash,\n\t\t\tTaskQueueID:  tqId,\n\t\t\tRangeID:      request.RangeID,\n\t\t\tData:         request.TaskQueueInfo.Data,\n\t\t\tDataEncoding: request.TaskQueueInfo.EncodingType.String(),\n\t\t}, m.version)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\trowsAffected, err := result.RowsAffected()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif rowsAffected != 1 {\n\t\t\treturn fmt.Errorf(\"%v rows were affected instead of 1\", rowsAffected)\n\t\t}\n\t\tresp = &persistence.UpdateTaskQueueResponse{}\n\t\treturn nil\n\t})\n\treturn resp, err\n}\n\nfunc (m *taskQueueStore) ListTaskQueue(\n\tctx context.Context,\n\trequest *persistence.ListTaskQueueRequest,\n) (*persistence.InternalListTaskQueueResponse, error) {\n\tpageToken := taskQueuePageToken{MinTaskQueueId: minTaskQueueId}\n\tif request.PageToken != nil {\n\t\tif err := gobDeserialize(request.PageToken, &pageToken); err != nil {\n\t\t\treturn nil, serviceerror.NewInternalf(\"error deserializing page token: %v\", err)\n\t\t}\n\t}\n\tvar err error","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/task_queues.go#L104-L140","documentation":"After an UpdateTaskQueue SQL statement executes, the code checks result.RowsAffected() and requires exactly 1 row to be modified. If the statement affected 0 or multiple rows, it returns this error, indicating the assumed single-row update invariant was violated (usually the task queue row did not exist or a range/condition matched unexpectedly).","triggerScenarios":"Calling persistence.UpdateTaskQueue when the task_queues row for the given (namespaceID, name, rangeID/kind) does not exist, or when a conditional UPDATE whose WHERE clause matches more than one row is executed.","commonSituations":"Task queue deleted concurrently by a reaper while being updated, stale rangeID causing the optimistic-condition UPDATE to match nothing, DB replication/divergence, running against a schema where the unique key assumptions don't hold.","solutions":["Verify the task queue exists (ListTaskQueue/DescribeTaskQueue) before updating and that namespaceID/name are correct.","Check for concurrent operations racing on the same task queue row; retry the operation or re-fetch rangeID after the conflict.","Confirm rangeID/range conditions passed to UpdateTaskQueue match current shard state; reload shard state if stale.","Inspect the DB row directly to see whether the expected row exists and whether the UPDATE WHERE clause could match multiple rows."],"exampleFix":"// before\nresp, err := p.UpdateTaskQueue(ctx, req) // rowsAffected == 0\n// after\nexisting, err := p.GetTaskQueue(ctx, getReq)\nif err != nil { return err }\nresp, err := p.UpdateTaskQueue(ctx, req) // with valid rangeID from existing","handlingStrategy":"retry","validationCode":"// pre-check the queue exists and rangeID is current\n_, err := persistenceStore.GetTaskQueue(ctx, &persistence.GetTaskQueueRequest{NamespaceID: nsID, Name: tqName, TaskType: taskType})","typeGuard":null,"tryCatchPattern":"resp, err := store.UpdateTaskQueue(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"rows were affected\") {\n    // re-fetch rangeID / shard state and retry once\n    return retryWithFreshRangeID(ctx, req)\n}\nreturn err","preventionTips":["Always pass a freshly loaded rangeID; never cache range state across retries.","Expect concurrency: task queue updates are racy, wrap in retry with backoff.","Confirm the queue wasn't deleted/recreated between get and update."],"tags":["go","persistence","sql","task-queue"],"backgroundTag":"unexpected-rows-affected","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}