{"record":{"id":"66a40a0c8934e66e","repo":"pola-rs/polars","slug":"extension-type-ext-name-is-already-registered","errorCode":null,"errorMessage":"extension type '{ext_name}' is already registered","messagePattern":"extension type '(.+?)' is already registered","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/datatypes/extension.py","lineNumber":30,"sourceCode":"\n\n@unstable()\ndef register_extension_type(\n    ext_name: str,\n    ext_class: type[dt.BaseExtension] | None = None,\n    *,\n    as_storage: bool = False,\n) -> None:\n    \"\"\"\n    Register the extension type for the given extension name.\n\n    .. warning::\n        This functionality is currently considered **unstable**. It may be\n        changed at any point without it being considered a breaking change.\n    \"\"\"\n    if \"ext_name\" in _REGISTRY:\n        msg = f\"extension type '{ext_name}' is already registered\"\n        raise ValueError(msg)\n\n    if as_storage:\n        assert ext_class is None, \"cannot specify ext_class when as_storage is True\"\n        _REGISTRY[ext_name] = \"storage\"\n        with contextlib.suppress(NameError):  # _plr module may be unavailable\n            _register_extension_type(ext_name, None)\n    else:\n        assert not as_storage, \"as_storage must be False when ext_class is provided\"\n        assert isinstance(ext_class, type)\n        assert issubclass(ext_class, dt.BaseExtension)\n        _REGISTRY[ext_name] = ext_class\n        with contextlib.suppress(NameError):  # _plr module may be unavailable\n            _register_extension_type(ext_name, ext_class)\n\n\n@unstable()\ndef unregister_extension_type(ext_name: str) -> None:\n    \"\"\"","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/datatypes/extension.py#L12-L48","documentation":"register_extension_type maintains a global _REGISTRY keyed by the extension name; registering the same extension type name twice raises ValueError. The registry can only hold one implementation per Arrow extension name, so duplicate registration is treated as a programming error.","triggerScenarios":"Calling polars.datatypes.extension.register_extension_type(MyType) twice (e.g. module-level registration executed again on re-import/reload, notebook cell re-run, or plugin imported under two paths); registering a name that ships registered in polars.","commonSituations":"Notebook re-execution of a registration cell; importlib.reload of a module containing top-level register_extension_type calls; duplicate plugin installs under different module names.","solutions":["Guard registration: only call if not already registered (use unregister_extension_type or check first).","Call unregister_extension_type(ext_name) before re-registering.","Move registration into an idempotent init function (module-level singleton / functools.cache)."],"exampleFix":"// before\nregister_extension_type(MyType)\n# ... cell re-run ...\nregister_extension_type(MyType)  # ValueError\n// after\nif MyType.__arrow_ext__name not registered:\n    register_extension_type(MyType)\n# or\nunregister_extension_type(MyType)\nregister_extension_type(MyType)","handlingStrategy":"try-catch","validationCode":"from polars.datatypes.extension import register_extension_type, unregister_extension_type\nimport contextlib\nwith contextlib.suppress(ValueError):\n    register_extension_type(MyType)  # idempotent registration","typeGuard":null,"tryCatchPattern":"try:\n    register_extension_type(MyType)\nexcept ValueError as e:\n    if \"already registered\" in str(e):\n        pass  # idempotent: already registered\n    else:\n        raise","preventionTips":["Wrap register_extension_type calls in an idempotent init guarded by a module-level flag","Unregister before re-registering during reloads","Avoid top-level registration in notebook cells that get re-executed"],"tags":["python","polars","extension","registry","duplicate-registration"],"backgroundTag":"file-already-exists","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}