apache/beam · error · RuntimeError

Model updates are currently not supported for KeyedModelHand

Error message

Model updates are currently not supported for KeyedModelHandlers with multiple different per-key ModelHandlers.

What it means

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.

Source

Thrown at sdks/python/apache_beam/ml/inference/base.py:1020

        cohort_id = old_cohort_id
        if old_cohort_id not in keys:
          # Create new cohort
          cohort_id = keys[0]
          for key in keys:
            self._key_to_id_map[key] = cohort_id
          mh = self._id_to_mh_map[old_cohort_id]
          self._id_to_mh_map[cohort_id] = deepcopy(mh)
        self._id_to_mh_map[cohort_id].update_model_path(updated_path)
        model.update_model_handler(cohort_id, updated_path, old_cohort_id)
        model_id = key_modelid_mapping[cohort_id]
        self._metrics_collectors[cohort_id] = _MetricsCollector(
            self._metrics_namespace, f'{cohort_id}-{model_id}-')

  def update_model_path(self, model_path: Optional[str] = None):
    if self._single_model:
      return self._unkeyed.update_model_path(model_path=model_path)
    if model_path is not None:
      raise RuntimeError(
          'Model updates are currently not supported for ' +
          'KeyedModelHandlers with multiple different per-key ' +
          'ModelHandlers.')

  def share_model_across_processes(self) -> bool:
    if self._single_model:
      return self._unkeyed.share_model_across_processes()
    return True

  def model_copies(self) -> int:
    if self._single_model:
      return self._unkeyed.model_copies()
    for mh in self._id_to_mh_map.values():
      if mh.model_copies() != 1:
        raise ValueError(
            'KeyedModelHandler cannot map records to multiple '
            'models if one or more of its ModelHandlers '
            'require multiple model copies (set via '

View on GitHub (pinned to 12126d8942)

Solutions

  1. Use update_model_paths with per-key update objects for multi-model KeyedModelHandlers.
  2. Only call update_model_path with a path when the handler wraps a single ModelHandler.
  3. If per-key handlers are actually identical/single-model, construct the handler so _single_model is True.

Example fix

// before
keyed_handler.update_model_path(model_path='gs://bucket/model_v2')
// after
keyed_handler.update_model_paths([
    UpdateModelPath(keys=['k1'], update_path='gs://bucket/model_v2', model_id='v2')])
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(h, KeyedModelHandler) and not h._single_model:
    raise TypeError('use update_model_paths for multi-model KeyedModelHandler')

Type guard

def supports_single_path_update(h) -> bool:
    return not isinstance(h, KeyedModelHandler) or h._single_model

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/f3d02afe97bba2a7. Report an issue: GitHub.