{"record":{"id":"f3d02afe97bba2a7","repo":"apache/beam","slug":"model-updates-are-currently-not-supported-for","errorCode":null,"errorMessage":"Model updates are currently not supported for KeyedModelHandlers with multiple different per-key ModelHandlers.","messagePattern":"Model updates are currently not supported for KeyedModelHandlers with multiple different per-key ModelHandlers\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/base.py","lineNumber":1020,"sourceCode":"        cohort_id = old_cohort_id\n        if old_cohort_id not in keys:\n          # Create new cohort\n          cohort_id = keys[0]\n          for key in keys:\n            self._key_to_id_map[key] = cohort_id\n          mh = self._id_to_mh_map[old_cohort_id]\n          self._id_to_mh_map[cohort_id] = deepcopy(mh)\n        self._id_to_mh_map[cohort_id].update_model_path(updated_path)\n        model.update_model_handler(cohort_id, updated_path, old_cohort_id)\n        model_id = key_modelid_mapping[cohort_id]\n        self._metrics_collectors[cohort_id] = _MetricsCollector(\n            self._metrics_namespace, f'{cohort_id}-{model_id}-')\n\n  def update_model_path(self, model_path: Optional[str] = None):\n    if self._single_model:\n      return self._unkeyed.update_model_path(model_path=model_path)\n    if model_path is not None:\n      raise RuntimeError(\n          'Model updates are currently not supported for ' +\n          'KeyedModelHandlers with multiple different per-key ' +\n          'ModelHandlers.')\n\n  def share_model_across_processes(self) -> bool:\n    if self._single_model:\n      return self._unkeyed.share_model_across_processes()\n    return True\n\n  def model_copies(self) -> int:\n    if self._single_model:\n      return self._unkeyed.model_copies()\n    for mh in self._id_to_mh_map.values():\n      if mh.model_copies() != 1:\n        raise ValueError(\n            'KeyedModelHandler cannot map records to multiple '\n            'models if one or more of its ModelHandlers '\n            'require multiple model copies (set via '","sourceCodeStart":1002,"sourceCodeEnd":1038,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/base.py#L1002-L1038","documentation":"Raised by KeyedModelHandler.update_model_path when a model_path is supplied for a multi-model (non-single) KeyedModelHandler. Hot model updates via a single path only work for single-model handlers; multi-per-key handlers must use update_model_paths instead.","triggerScenarios":"Calling update_model_path(model_path='gs://...') on a KeyedModelHandler constructed from a dict of multiple per-key ModelHandlers (i.e. _single_model is False).","commonSituations":"Reusing single-handler update code against a keyed multi-model handler; calling update_model_path instead of update_model_paths after switching to per-key handlers.","solutions":["Use update_model_paths with per-key update objects for multi-model KeyedModelHandlers.","Only call update_model_path with a path when the handler wraps a single ModelHandler.","If per-key handlers are actually identical/single-model, construct the handler so _single_model is True."],"exampleFix":"// before\nkeyed_handler.update_model_path(model_path='gs://bucket/model_v2')\n// after\nkeyed_handler.update_model_paths([\n    UpdateModelPath(keys=['k1'], update_path='gs://bucket/model_v2', model_id='v2')])","handlingStrategy":"validation","validationCode":"if isinstance(h, KeyedModelHandler) and not h._single_model:\n    raise TypeError('use update_model_paths for multi-model KeyedModelHandler')","typeGuard":"def supports_single_path_update(h) -> bool:\n    return not isinstance(h, KeyedModelHandler) or h._single_model","tryCatchPattern":null,"preventionTips":["Route update calls through a helper that picks update_model_path vs update_model_paths based on handler type.","Never hardcode update_model_path in shared pipeline code."],"tags":["python","apache-beam","ml-inference","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}