{"record":{"id":"8827890613154533","repo":"apache/beam","slug":"no-window-for-s","errorCode":null,"errorMessage":"No window for %s","messagePattern":"No window for (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/trigger.py","lineNumber":1191,"sourceCode":"  def merge(self, to_be_merged, merge_result):\n    for window in to_be_merged:\n      if window != merge_result:\n        if window in self.window_ids:\n          if merge_result in self.window_ids:\n            merge_window_ids = self.window_ids[merge_result]\n          else:\n            merge_window_ids = self.window_ids[merge_result] = []\n          merge_window_ids.extend(self.window_ids.pop(window))\n          self._persist_window_ids()\n\n  def known_windows(self):\n    return list(self.window_ids)\n\n  def get_window(self, window_id):\n    for window, ids in self.window_ids.items():\n      if window_id in ids:\n        return window\n    raise ValueError('No window for %s' % window_id)\n\n  def _get_id(self, window):\n    if window in self.window_ids:\n      return self.window_ids[window][0]\n\n    window_id = self._get_next_counter()\n    self.window_ids[window] = [window_id]\n    self._persist_window_ids()\n    return window_id\n\n  def _get_ids(self, window):\n    return self.window_ids.get(window, [])\n\n  def _get_next_counter(self):\n    if not self.window_ids:\n      self.counter = 0\n    elif self.counter is None:\n      self.counter = max(k for ids in self.window_ids.values() for k in ids)","sourceCodeStart":1173,"sourceCodeEnd":1209,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/trigger.py#L1173-L1209","documentation":"MergingTriggerState.get_window looks up which window owns a given window_id by scanning window_ids and raises ValueError('No window for %s') when the id is not registered. This indicates the caller is using a stale or foreign window id that the state driver never assigned.","triggerScenarios":"Calling get_state/clear_state or trigger callbacks with a window_id that was never created via _get_id, or one already removed when windows were cleaned up after being fired/garbage-collected.","commonSituations":"Custom trigger drivers holding window ids across pane firings after the state was cleaned; timers firing for windows already garbage-collected; retaining ids from a previous bundle/retry.","solutions":["Obtain window ids only from the state driver (window_ids / _get_id) and never invent or cache them across cleanup.","Clear any stored window ids when windows are output/garbage-collected; re-derive them for late data.","Add a lookup guard before use: check the id exists in the driver's window_ids before calling APIs that resolve it."],"exampleFix":"// before\nstate.get_state(window_id, tag)  # window_id from an old firing\n// after\nif window_id in [i for ids in state.window_ids.values() for i in ids]:\n    state.get_state(window_id, tag)","handlingStrategy":"validation","validationCode":"known_ids = {i for ids in state.window_ids.values() for i in ids}\nassert window_id in known_ids, f'stale window_id {window_id}'","typeGuard":"def has_window_id(state, window_id):\n    return any(window_id in ids for ids in state.window_ids.values())","tryCatchPattern":"try:\n    window = state.get_window(window_id)\nexcept ValueError:\n    window = None  # window was cleaned up; skip stale callback","preventionTips":["Never cache window ids across pane firings or bundle retries.","Clear stored ids when windows are output/garbage-collected.","Resolve ids via the driver's own window_ids mapping only."],"tags":["python","apache-beam","trigger","state","window"],"backgroundTag":"resource-not-found","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"}