apache/beam · error · ValueError

Faled loading session: expected dict, got {}

Error message

Faled loading session: expected dict, got {}

What it means

load_session() unpickles a previously saved registry file and requires the top-level object to be a dict of registries (coder, logical_type, etc.). If cloudpickle.load returns anything else, ValueError is raised. Note the message uses {} with str.format-style braces but the call passes the type as a second positional arg, so the placeholder is not actually filled — a library bug, but the condition is clear.

Source

Thrown at sdks/python/apache_beam/internal/cloudpickle_pickler.py:284

    pickler = cloudpickle.CloudPickler(file)
    # TODO(https://github.com/apache/beam/issues/18500) add file system registry
    # once implemented
    pickler.dump({
        "coder": coder_reg,
        "logical_type": logical_type_reg,
        "schema": schema_reg
    })


def load_session(file_path):
  from apache_beam.coders import typecoders
  from apache_beam.typehints import schemas
  from apache_beam.typehints.schema_registry import SCHEMA_REGISTRY

  with _pickle_lock, open(file_path, 'rb') as file:
    registries = cloudpickle.load(file)
    if type(registries) != dict:
      raise ValueError(
          "Faled loading session: expected dict, got {}", type(registries))
    if "coder" in registries:
      typecoders.registry.load_custom_type_coder_tuples(registries["coder"])
    else:
      _LOGGER.warning('No coder registry found in saved session')
    if "logical_type" in registries:
      schemas.LogicalType._known_logical_types.load(registries["logical_type"])
    else:
      _LOGGER.warning('No logical type registry found in saved session')
    if "schema" in registries:
      SCHEMA_REGISTRY.load_registered_typings(registries["schema"])
    else:
      _LOGGER.warning('No schema registry found in saved session')

View on GitHub (pinned to 12126d8942)

Solutions

  1. Ensure the file was created with apache_beam.internal.cloudpickle_pickler.dump_session.
  2. Regenerate the session file with your current Beam version.
  3. Check you are not loading a stale or truncated file; validate with a fresh dump/load round-trip.
  4. Catch ValueError around load_session and fall back to a fresh (empty) session.

Example fix

// before
load_session('pipeline.pkl')  # wrong file
// after
from apache_beam.internal import cloudpickle_pickler
cloudpickle_pickler.dump_session('session.pkl')
cloudpickle_pickler.load_session('session.pkl')
Defensive patterns

Strategy: validation

Validate before calling

import cloudpickle
with open(path, 'rb') as f:
    data = cloudpickle.load(f)
if not isinstance(data, dict):
    raise TypeError(f'{path} is not a beam session dump')

Type guard

def is_session_file(path: str) -> bool:
    try:
        from apache_beam.internal import cloudpickle_pickler
        return True  # validate via dump/load round trip in staging
    except Exception:
        return False

Try / catch

try:
    load_session(file_path)
except ValueError as e:
    if 'Faled loading session' in str(e):
        _LOGGER.warning('Bad session file; starting fresh')
    else:
        raise

Prevention

When it happens

Trigger: Calling apache_beam.internal.cloudpickle_pickler.load_session(path) on a file that was not written by dump_session, or that contains a non-dict pickle (e.g. a list, a pickled pipeline object, or corrupt/truncated data).

Common situations: Pointing load_session at the wrong file; loading a file produced by plain pickle.dump; schema-registry format changed between Beam versions.

Related errors


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