{"record":{"id":"7d37396c1aeeed86","repo":"temporalio/temporal","slug":"rowsaffected-returned-error-for-shardid-v-v","errorCode":null,"errorMessage":"rowsAffected returned error for shardID %v: %v","messagePattern":"rowsAffected returned error for shardID (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/persistence/sql/shard.go","lineNumber":106,"sourceCode":"\t\t\ttx,\n\t\t\trequest.ShardID,\n\t\t\trequest.PreviousRangeID,\n\t\t\tm.logger,\n\t\t); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tresult, err := tx.UpdateShards(ctx, &sqlplugin.ShardsRow{\n\t\t\tShardID:      request.ShardID,\n\t\t\tRangeID:      request.RangeID,\n\t\t\tData:         request.ShardInfo.Data,\n\t\t\tDataEncoding: request.ShardInfo.EncodingType.String(),\n\t\t})\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 fmt.Errorf(\"rowsAffected returned error for shardID %v: %v\", request.ShardID, err)\n\t\t}\n\t\tif rowsAffected != 1 {\n\t\t\treturn fmt.Errorf(\"rowsAffected returned %v shards instead of one\", rowsAffected)\n\t\t}\n\t\treturn nil\n\t})\n}\n\nfunc (m *sqlShardStore) AssertShardOwnership(\n\tctx context.Context,\n\trequest *persistence.AssertShardOwnershipRequest,\n) error {\n\t// AssertShardOwnership is not implemented for sql shard store\n\treturn nil\n}\n\n// initiated by the owning shard\nfunc lockShard(","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/persistence/sql/shard.go#L88-L124","documentation":"In the SQL shard store's create-shard path, after inserting the shard row the driver's result.RowsAffected() is called to confirm success; if that call itself errors, the shardID and underlying driver error are wrapped and returned. The insert may still have succeeded but cannot be verified.","triggerScenarios":"Creating a shard row (no existing shard) where the SQL driver's RowsAffected fails right after the INSERT — typically a driver limitation or a broken/dead connection immediately after execution.","commonSituations":"Unsupported or misbehaving database driver; connection killed between statement execution and RowsAffected; custom drivers (e.g., some proxies/wrappers) that don't implement affected-row counts.","solutions":["Read the wrapped driver error in the message for the root cause and fix connectivity or driver configuration.","Upgrade the database driver (go-sql-driver/mysql, lib/pq) to a version with correct RowsAffected support.","Confirm the backend is officially supported; proxies like some connection poolers can strip affected-row info.","Retry shard creation; if the insert actually committed, the next attempt should take the existing-shard path instead."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := createShard(ctx); err != nil {\n    if strings.Contains(err.Error(), \"rowsAffected returned error for shardID\") {\n        // transient driver/connection issue; retry with backoff\n        return retryWithBackoff(createShard)\n    }\n    return err\n}","preventionTips":["Keep SQL drivers updated and use officially supported databases.","Avoid DB proxies that strip result metadata like affected-row counts.","Watch connection-pool errors; stale connections can fail between execute and RowsAffected."],"tags":["database","sql-driver","shard","persistence"],"backgroundTag":"rows-affected-unsupported","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}