{"record":{"id":"007d8f6211cb73e2","repo":"apache/beam","slug":"bucket-boundaries-must-be-a-non-empty-sorted-list-of","errorCode":null,"errorMessage":"bucket_boundaries must be a non-empty sorted list of positive values.","messagePattern":"bucket_boundaries must be a non-empty sorted list of positive values\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/util.py","lineNumber":1091,"sourceCode":"      min_batch_size=1,\n      max_batch_size=10000,\n      target_batch_overhead=.05,\n      target_batch_duration_secs=10,\n      target_batch_duration_secs_including_fixed_cost=None,\n      max_batch_duration_secs=None,\n      *,\n      element_size_fn=lambda x: 1,\n      variance=0.25,\n      clock=time.time,\n      record_metrics=True,\n      length_fn=None,\n      bucket_boundaries=None):\n    if bucket_boundaries is not None and length_fn is None:\n      raise ValueError('bucket_boundaries requires length_fn to be set.')\n    if bucket_boundaries is not None:\n      if (not bucket_boundaries or any(b <= 0 for b in bucket_boundaries) or\n          bucket_boundaries != sorted(bucket_boundaries)):\n        raise ValueError(\n            'bucket_boundaries must be a non-empty sorted list of '\n            'positive values.')\n    self._batch_size_estimator = _BatchSizeEstimator(\n        min_batch_size=min_batch_size,\n        max_batch_size=max_batch_size,\n        target_batch_overhead=target_batch_overhead,\n        target_batch_duration_secs=target_batch_duration_secs,\n        target_batch_duration_secs_including_fixed_cost=(\n            target_batch_duration_secs_including_fixed_cost),\n        variance=variance,\n        clock=clock,\n        record_metrics=record_metrics)\n    self._element_size_fn = element_size_fn\n    self._max_batch_dur = max_batch_duration_secs\n    self._clock = clock\n    self._length_fn = length_fn\n    if length_fn is not None and bucket_boundaries is None:\n      self._bucket_boundaries = self._DEFAULT_BUCKET_BOUNDARIES","sourceCodeStart":1073,"sourceCodeEnd":1109,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/util.py#L1073-L1109","documentation":"Raised when BatchElements' bucket_boundaries is provided but invalid: empty, containing non-positive values, or not sorted ascending. Bucket boundaries define increasing edges between batch-size buckets, so they must be a non-empty, strictly positive, sorted list.","triggerScenarios":"BatchElements(bucket_boundaries=[], length_fn=len); boundaries with 0 or negative values ([0, 10, 100]); unsorted boundaries ([100, 10]).","commonSituations":"Building boundaries programmatically (e.g. from a dict or set, losing order); including 0 as a lower bound; sorting descending by mistake; filtering that removed all boundaries.","solutions":["Sort ascending and ensure all values are > 0: boundaries = sorted(b for b in boundaries if b > 0).","Guard for emptiness before constructing: if not boundaries: skip bucket_boundaries or use defaults.","Sanity-check the list: assert boundaries == sorted(boundaries) and all(b > 0 for b in boundaries).","If generating from a set/dict, convert via sorted() to fix ordering."],"exampleFix":"// before\nbeam.BatchElements(bucket_boundaries=[100, 10, 0], length_fn=len)\n\n// after\nboundaries = sorted(b for b in [100, 10, 0] if b > 0)  # [10, 100]\nbeam.BatchElements(bucket_boundaries=boundaries, length_fn=len)","handlingStrategy":"validation","validationCode":"if bucket_boundaries is not None:\n    assert bucket_boundaries, 'bucket_boundaries must be non-empty'\n    assert all(b > 0 for b in bucket_boundaries), 'bucket_boundaries must be positive'\n    assert bucket_boundaries == sorted(bucket_boundaries), 'bucket_boundaries must be sorted ascending'","typeGuard":"def valid_bucket_boundaries(bounds):\n    return (isinstance(bounds, (list, tuple)) and len(bounds) > 0\n            and all(isinstance(b, (int, float)) and b > 0 for b in bounds)\n            and list(bounds) == sorted(bounds))","tryCatchPattern":"try:\n    t = beam.BatchElements(bucket_boundaries=bounds, length_fn=length_fn)\nexcept ValueError as e:\n    if 'bucket_boundaries must be' in str(e):\n        bounds = sorted({b for b in bounds if b > 0})\n        t = beam.BatchElements(bucket_boundaries=bounds, length_fn=length_fn)\n    else:\n        raise","preventionTips":["Normalize boundaries with sorted(b for b in bounds if b > 0) before passing.","Never build boundaries from sets/dicts without sorting.","Exclude 0 and negatives explicitly; boundaries are edges above the minimum, not inclusive lower bounds."],"tags":["python","apache-beam","batchelements","config-validation"],"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"}