{"record":{"id":"11e11330ed82655b","repo":"jax-ml/jax","slug":"malformed-pickled-dictkey-expected-1-tuple","errorCode":null,"errorMessage":"Malformed pickled DictKey, expected 1-tuple","messagePattern":"Malformed pickled DictKey, expected 1-tuple","errorType":"exception","errorClass":"XlaRuntimeError","httpStatus":null,"severity":"error","filePath":"jaxlib/pytree.cc","lineNumber":1958,"sourceCode":"                     new (&key) SequenceKey(nb::cast<int>(state[0]));\n                   });\n\n  nb::class_<DictKey> dict_key(pytree, \"DictKey\",\n                               nb::type_slots(DictKey::slots_),\n                               nb::sig(\"class DictKey(typing.Hashable)\"));\n  dict_key.def(nb::init<nb::object>(), nb::arg(\"key\").none());\n  dict_key.def(\"__str__\", &DictKey::ToString);\n  dict_key.def(\"__repr__\", &DictKey::ToReprString);\n  dict_key.def(\"__eq__\", &DictKey::Equals);\n  dict_key.def(\"__hash__\",\n               [](const DictKey& key) { return nanobind::hash(key.key()); });\n  dict_key.def_prop_ro(\"key\", &DictKey::key);\n  dict_key.def_prop_ro_static(\"__match_args__\", &DictKey::MatchArgs);\n  dict_key.def(\"__getstate__\",\n               [](DictKey& key) { return nb::make_tuple(key.key()); });\n  dict_key.def(\"__setstate__\", [](DictKey& key, const nb::tuple& state) {\n    if (state.size() != 1) {\n      throw xla::XlaRuntimeError(\"Malformed pickled DictKey, expected 1-tuple\");\n    }\n    new (&key) DictKey(nb::cast<nb::object>(state[0]));\n  });\n\n  nb::class_<GetAttrKey> get_attr_key(\n      pytree, \"GetAttrKey\", nb::sig(\"class GetAttrKey(typing.Hashable)\"));\n  get_attr_key.def(nb::init<nb::str>(), nb::arg(\"name\"));\n  get_attr_key.def(\"__str__\", &GetAttrKey::ToString);\n  get_attr_key.def(\"__repr__\", &GetAttrKey::ToReprString);\n  get_attr_key.def(\"__eq__\", &GetAttrKey::Equals);\n  get_attr_key.def(\"__hash__\",\n                   [](const GetAttrKey& key) { return nb::hash(key.name()); });\n  get_attr_key.def_prop_ro(\"name\", &GetAttrKey::name);\n  get_attr_key.def_prop_ro_static(\"__match_args__\", &GetAttrKey::MatchArgs);\n  get_attr_key.def(\"__getstate__\",\n                   [](GetAttrKey& key) { return nb::make_tuple(key.name()); });\n  get_attr_key.def(\"__setstate__\", [](GetAttrKey& key, const nb::tuple& state) {\n    if (state.size() != 1) {","sourceCodeStart":1940,"sourceCodeEnd":1976,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/pytree.cc#L1940-L1976","documentation":"DictKey.__setstate__ requires pickled state to be a 1-tuple holding the key object. A state tuple with more or fewer elements raises this error.","triggerScenarios":"Unpickling a jaxlib.pytree.DictKey whose state was altered or serialized by an incompatible version.","commonSituations":"Version-skewed pickles of treedef paths; manually assembled pickle payloads in tests or debugging tools.","solutions":["Regenerate pickles with the current jaxlib","Ensure identical jaxlib versions when transferring pickled treedefs","Avoid mutating __getstate__ output"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def valid_dict_key_state(s) -> bool:\n    return isinstance(s, tuple) and len(s) == 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use __getstate__/__setstate__ round-trips only within one jaxlib version"],"tags":["jax","pytree","pickle"],"backgroundTag":"pickle-format-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}