{"record":{"id":"e55ecb45b3770901","repo":"apache/beam","slug":"element","errorCode":null,"errorMessage":"{element}","messagePattern":"\\{element\\}","errorType":"exception","errorClass":"OverflowError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/cy_combiners.py","lineNumber":95,"sourceCode":"    self.value += n\n\n  def merge(self, accumulators):\n    for accumulator in accumulators:\n      self.value += accumulator.value\n\n  def extract_output(self):\n    return self.value\n\n\nclass SumInt64Accumulator(object):\n  def __init__(self):\n    self.value = 0\n\n  def add_input(self, element):\n    global INT64_MAX, INT64_MIN  # pylint: disable=global-variable-not-assigned\n    element = int(element)\n    if not INT64_MIN <= element <= INT64_MAX:\n      raise OverflowError(element)\n    self.value += element\n\n  def add_input_n(self, element, n):\n    global INT64_MAX, INT64_MIN  # pylint: disable=global-variable-not-assigned\n    element = int(element)\n    if not INT64_MIN <= element <= INT64_MAX:\n      raise OverflowError(element)\n    self.value += element * n\n\n  def merge(self, accumulators):\n    for accumulator in accumulators:\n      self.value += accumulator.value\n\n  def extract_output(self):\n    if not INT64_MIN <= self.value <= INT64_MAX:\n      self.value %= 2**64\n      if self.value >= INT64_MAX:\n        self.value -= 2**64","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/cy_combiners.py#L77-L113","documentation":"Raised by CySumInt64.add_input in cy_combiners.py when an element added to the int64 sum accumulator, after conversion with int(), falls outside the signed 64-bit range [INT64_MIN, INT64_MAX]. An OverflowError carrying the offending element is thrown to protect the CyC-backed accumulator from overflowing.","triggerScenarios":"Calling add_input (directly or via beam.Combine with sum over int64) with a value like 2**63 or -2**63-1, or a float/object that int()-converts to such a magnitude.","commonSituations":"Aggregating huge counters or pre-summed values; accidentally passing floats like 1e30; summing in a pipeline whose sink declares INT64 while data was assumed unbounded Python ints.","solutions":["Clamp or validate input values to fit in int64 before combining.","Use the plain Python (arbitrary-precision) sum combiner instead of the Cython int64 variant.","Aggregate in stages (e.g. per-key partial sums) or switch the sink type to a wider representation if supported.","Check for data errors producing absurd magnitudes (e.g. unit or scaling bugs)."],"exampleFix":"// before\nelements | beam.CombineGlobally(beam.combiners.SumCombineFn())  # element 2**63\n// after\nvalidated = elements | beam.Filter(lambda x: -2**63 < x < 2**63-1)","handlingStrategy":"validation","validationCode":"INT64_MIN, INT64_MAX = -2**63, 2**63 - 1\ndef fits_int64(x):\n    return INT64_MIN <= int(x) <= INT64_MAX\npcoll = pcoll | beam.Filter(fits_int64)","typeGuard":"def is_int64(x):\n    try:\n        return -2**63 <= int(x) <= 2**63 - 1\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    total = pcoll | beam.CombineGlobally(beam.combiners.SumCombineFn())\nexcept OverflowError as e:\n    logging.error('int64 sum overflow for element %s', e)\n    raise","preventionTips":["Add a range assertion at pipeline ingestion.","Prefer pure-Python combiners when values may exceed int64.","Beware floats like 1e30 that convert to huge ints."],"tags":["python","apache-beam","overflow","int64","combiner"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}