{"record":{"id":"2d7cc1fe7d468792","repo":"apache/beam","slug":"max-partitions-must-be-greater-than-0","errorCode":null,"errorMessage":"max partitions must be greater than 0","messagePattern":"max partitions must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/spannerio/query_options.go","lineNumber":65,"sourceCode":"\t}\n\n\treturn opts\n}\n\n// WithBatching sets whether we will use a batched reader. Batching is set to true by default, disable it when the\n// underlying query is not root-partitionable.\nfunc WithBatching(batching bool) QueryOptionFn {\n\treturn func(opts *queryOptions) error {\n\t\topts.Batching = batching\n\t\treturn nil\n\t}\n}\n\n// WithMaxPartitions sets the maximum number of Partitions to split the query into when batched reading.\nfunc WithMaxPartitions(maxPartitions int64) QueryOptionFn {\n\treturn func(opts *queryOptions) error {\n\t\tif maxPartitions <= 0 {\n\t\t\treturn errors.New(\"max partitions must be greater than 0\")\n\t\t}\n\n\t\topts.MaxPartitions = maxPartitions\n\t\treturn nil\n\t}\n}\n\n// WithTimestampBound sets the TimestampBound to use when doing batched reads.\nfunc WithTimestampBound(timestampBound spanner.TimestampBound) QueryOptionFn {\n\treturn func(opts *queryOptions) error {\n\t\topts.TimestampBound = timestampBound\n\t\treturn nil\n\t}\n}\n","sourceCodeStart":47,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/spannerio/query_options.go#L47-L80","documentation":"This error comes from the Spanner IO query option helper WithMaxPartitions, which configures the maximum number of partitions a batched Spanner query read is split into. The library validates the supplied value and rejects it when it is zero or negative, because Spanner requires at least one partition to execute a batched read. It is a fail-fast guard against an unusable configuration.","triggerScenarios":"Calling beam/io/spannerio WithMaxPartitions(maxPartitions) with a value <= 0, e.g. a zero default from an unset config variable, a negative value from a misparsed CLI flag, or a computed size that divided down to 0.","commonSituations":"Developers wiring the max partitions value from environment variables, flags, or pipeline options without validating numeric parsing; empty/absent config yields 0 which fails here.","solutions":["Pass a positive int64, e.g. WithMaxPartitions(1024)","Validate/parse the source config before constructing options and substitute a sane default (e.g. >= 1) when unset"],"exampleFix":"// before\nopts, err := spannerio.WithMaxPartitions(maxPartitions) // maxPartitions = 0 from unset flag\n// after\nif maxPartitions <= 0 {\n    maxPartitions = 1024\n}\nopts, err := spannerio.WithMaxPartitions(maxPartitions)","handlingStrategy":"validation","validationCode":"func validMaxPartitions(n int64) bool { return n > 0 }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default maxPartitions to a positive constant when the config value is unset","Parse numeric flags with strconv.ParseInt and check the error and sign before use"],"tags":["go","config-validation","spanner"],"backgroundTag":"invalid-config-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}