{"record":{"id":"429a3486aee33e12","repo":"jax-ml/jax","slug":"duplicate-serialization-registration-for-type-no","errorCode":null,"errorMessage":"Duplicate serialization registration for type `{nodetype}`. Previous registration was with serialized_name `{serialization_registry[nodetype][0]}`.","messagePattern":"Duplicate serialization registration for type `(.+?)`\\. Previous registration was with serialized_name `(.+?)`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/export/_export.py","lineNumber":432,"sourceCode":"    deserialize_auxdata: deserialize the auxdata that was serialized by the\n      ``serialize_auxdata``.\n    from_children: if present, this is a function that takes that result of\n      ``deserialize_auxdata`` along with some children and creates an instance\n      of ``nodetype``. This is similar to the ``unflatten_func`` passed to\n      :func:`jax.tree_util.register_pytree_node`. If not present, we look up\n      and use the ``unflatten_func``. This is needed for ``collections.namedtuple``,\n      which does not have a ``register_pytree_node``, but it can be useful to\n      override that function. Note that the result of ``from_children`` is\n      only used with :func:`jax.tree_util.tree_structure` to construct a proper\n      PyTree node, it is not used to construct the outputs of the serialized\n      function.\n\n  Returns:\n    the same type passed as ``nodetype``, so that this function can\n    be used as a class decorator.\n  \"\"\"\n  if nodetype in serialization_registry:\n    raise ValueError(\n        f\"Duplicate serialization registration for type `{nodetype}`. \"\n        \"Previous registration was with serialized_name \"\n        f\"`{serialization_registry[nodetype][0]}`.\")\n  if serialized_name in deserialization_registry:\n    raise ValueError(\n        \"Duplicate serialization registration for \"\n        f\"serialized_name `{serialized_name}`. \"\n        \"Previous registration was for type \"\n        f\"`{deserialization_registry[serialized_name][0]}`.\")\n  if from_children is None:\n    if nodetype not in tree_util._registry:\n      raise ValueError(\n          f\"If `from_children` is not present, you must call first\"\n          f\"`jax.tree_util.register_pytree_node` for `{nodetype}`\")\n    from_children = tree_util._registry[nodetype].from_iter\n\n  serialization_registry[nodetype] = (\n      serialized_name, serialize_auxdata)","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/_export.py#L414-L450","documentation":"jax.experimental.export.register_pytree_node_serialization registers a custom pytree type for serialization under a name. Registering the same Python type twice — e.g. calling the registration decorator/function again (often due to module re-import or notebook re-execution) — raises this ValueError naming the previous serialized_name.","triggerScenarios":"Re-running a notebook cell containing @register_pytree_node_serialization(MyType, 'my_type'); re-importing a registration module after importlib.reload; registering the same class in two libraries/plugins.","commonSituations":"Jupyter/Colab iterative development; hot-reload in web frameworks; two versions of a helper module both performing registration; test suites importing registration code more than once.","solutions":["Make registration idempotent: skip if already registered (check the registry before calling)","Use importlib.reload carefully; restart the kernel after editing registration code in notebooks","Consolidate registration into a single module imported once"],"exampleFix":"# before\nfrom jax.experimental.export import register_pytree_node_serialization\nregister_pytree_node_serialization(MyType, 'my_type')  # re-run -> ValueError\n\n# after\nfrom jax.experimental import export\nif MyType not in export.serialization_registry:\n    register_pytree_node_serialization(MyType, 'my_type')","handlingStrategy":"validation","validationCode":"from jax.experimental import export\nif MyType not in export.serialization_registry:\n    register_pytree_node_serialization(MyType, 'my_type')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap registrations in idempotence checks (registry membership test)","Centralize all registrations in one module imported exactly once","Restart kernels after editing registration cells in notebooks"],"tags":["jax","export","serialization","registry","duplicate-registration"],"backgroundTag":"duplicate-registration","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}