{"record":{"id":"4bbdd37113309805","repo":"apache/beam","slug":"the-size-parameter-must-be-strictly-positive","errorCode":null,"errorMessage":"The size parameter must be strictly positive.","messagePattern":"The size parameter must be strictly positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/window.py","lineNumber":417,"sourceCode":"  Attributes:\n    size: Size of the window as seconds.\n    offset: Offset of this window as seconds. Windows start at\n      t=N * size + offset where t=0 is the UNIX epoch. The offset must be a\n      value in range [0, size). If it is not it will be normalized to this\n      range.\n  \"\"\"\n  def __init__(self, size: DurationTypes, offset: TimestampTypes = 0):\n    \"\"\"Initialize a ``FixedWindows`` function for a given size and offset.\n\n    Args:\n      size (int): Size of the window in seconds.\n      offset(int): Offset of this window as seconds. Windows start at\n        t=N * size + offset where t=0 is the UNIX epoch. The offset must be a\n        value in range [0, size). If it is not it will be normalized to this\n        range.\n    \"\"\"\n    if size <= 0:\n      raise ValueError('The size parameter must be strictly positive.')\n    self.size = Duration.of(size)\n    self.offset = Timestamp.of(offset) % self.size\n\n  def assign(self, context: WindowFn.AssignContext) -> list[IntervalWindow]:\n    timestamp = context.timestamp\n    start = timestamp - (timestamp - self.offset) % self.size\n    return [IntervalWindow(start, start + self.size)]\n\n  def get_window_coder(self) -> coders.IntervalWindowCoder:\n    return coders.IntervalWindowCoder()\n\n  def __eq__(self, other):\n    if type(self) == type(other) == FixedWindows:\n      return self.size == other.size and self.offset == other.offset\n\n  def __hash__(self):\n    return hash((self.size, self.offset))\n","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/window.py#L399-L435","documentation":"FixedWindows requires the window size to be strictly positive (size > 0); the constructor raises ValueError otherwise. The size defines the fixed window width in seconds and zero/negative widths are meaningless.","triggerScenarios":"FixedWindows(0), FixedWindows(-30), or size computed from a config/flag that resolved to 0 (e.g. int('0'), a missing timedelta converted to seconds).","commonSituations":"Window duration parsed from CLI/env defaulting to 0; dividing a total duration by a count that is 0 or huge; unit confusion where milliseconds value was meant as seconds and rounded to 0.","solutions":["Pass a strictly positive duration, e.g. FixedWindows(60)","Validate the config value before constructing: assert window_seconds > 0","Fix unit conversion so the duration isn't truncated to 0 (use timedelta.total_seconds())"],"exampleFix":"// before\nwindow_secs = int(os.getenv('WINDOW_SECS', '0'))\nbeam.WindowInto(FixedWindows(window_secs))\n// after\nwindow_secs = int(os.getenv('WINDOW_SECS', '60'))\nassert window_secs > 0\nbeam.WindowInto(FixedWindows(window_secs))","handlingStrategy":"validation","validationCode":"if window_size <= 0:\n    raise ValueError('window_size must be > 0')","typeGuard":"def valid_window_size(v): return isinstance(v, (int, float)) and v > 0","tryCatchPattern":null,"preventionTips":["Default window durations to sane positive values","Convert durations with timedelta.total_seconds() to avoid truncation","Validate CLI/env-supplied durations before building the pipeline"],"tags":["python","apache-beam","windowing","constructor","validation"],"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-14T21:17:11.552Z"}