{"record":{"id":"d33056bad447af5b","repo":"apache/beam","slug":"faled-loading-session-expected-dict-got","errorCode":null,"errorMessage":"Faled loading session: expected dict, got {}","messagePattern":"Faled loading session: expected dict, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/internal/cloudpickle_pickler.py","lineNumber":284,"sourceCode":"    pickler = cloudpickle.CloudPickler(file)\n    # TODO(https://github.com/apache/beam/issues/18500) add file system registry\n    # once implemented\n    pickler.dump({\n        \"coder\": coder_reg,\n        \"logical_type\": logical_type_reg,\n        \"schema\": schema_reg\n    })\n\n\ndef load_session(file_path):\n  from apache_beam.coders import typecoders\n  from apache_beam.typehints import schemas\n  from apache_beam.typehints.schema_registry import SCHEMA_REGISTRY\n\n  with _pickle_lock, open(file_path, 'rb') as file:\n    registries = cloudpickle.load(file)\n    if type(registries) != dict:\n      raise ValueError(\n          \"Faled loading session: expected dict, got {}\", type(registries))\n    if \"coder\" in registries:\n      typecoders.registry.load_custom_type_coder_tuples(registries[\"coder\"])\n    else:\n      _LOGGER.warning('No coder registry found in saved session')\n    if \"logical_type\" in registries:\n      schemas.LogicalType._known_logical_types.load(registries[\"logical_type\"])\n    else:\n      _LOGGER.warning('No logical type registry found in saved session')\n    if \"schema\" in registries:\n      SCHEMA_REGISTRY.load_registered_typings(registries[\"schema\"])\n    else:\n      _LOGGER.warning('No schema registry found in saved session')\n","sourceCodeStart":266,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/internal/cloudpickle_pickler.py#L266-L298","documentation":"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.","triggerScenarios":"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).","commonSituations":"Pointing load_session at the wrong file; loading a file produced by plain pickle.dump; schema-registry format changed between Beam versions.","solutions":["Ensure the file was created with apache_beam.internal.cloudpickle_pickler.dump_session.","Regenerate the session file with your current Beam version.","Check you are not loading a stale or truncated file; validate with a fresh dump/load round-trip.","Catch ValueError around load_session and fall back to a fresh (empty) session."],"exampleFix":"// before\nload_session('pipeline.pkl')  # wrong file\n// after\nfrom apache_beam.internal import cloudpickle_pickler\ncloudpickle_pickler.dump_session('session.pkl')\ncloudpickle_pickler.load_session('session.pkl')","handlingStrategy":"validation","validationCode":"import cloudpickle\nwith open(path, 'rb') as f:\n    data = cloudpickle.load(f)\nif not isinstance(data, dict):\n    raise TypeError(f'{path} is not a beam session dump')","typeGuard":"def is_session_file(path: str) -> bool:\n    try:\n        from apache_beam.internal import cloudpickle_pickler\n        return True  # validate via dump/load round trip in staging\n    except Exception:\n        return False","tryCatchPattern":"try:\n    load_session(file_path)\nexcept ValueError as e:\n    if 'Faled loading session' in str(e):\n        _LOGGER.warning('Bad session file; starting fresh')\n    else:\n        raise","preventionTips":["Only load files produced by dump_session.","Verify Beam version parity between dump and load.","Keep session files separate from ordinary pickle artifacts."],"tags":["python","apache-beam","deserialization","session"],"backgroundTag":"unexpected-response-shape","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"}