{"record":{"id":"e3b46a250cfb3552","repo":"slint-ui/slint","slug":"callback-name-cannot-be-used-with-a-callback-decorator-for","errorCode":null,"errorMessage":"Callback '${name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component","messagePattern":"Callback '(.+?)' cannot be used with a callback decorator for an async function, as it is not declared in Slint component","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"api/python/slint/slint/__init__.py","lineNumber":188,"sourceCode":"                is_async = getattr(value, \"slint.async\", False)\n                if is_async:\n                    if \"global_name\" in callback_info:\n                        global_name = callback_info[\"global_name\"]\n                        is_void = compdef.global_callback_returns_void(\n                            global_name, name\n                        )\n                        if is_void is None:\n                            raise AttributeError(\n                                f\"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component\"\n                            )\n                        if not is_void:\n                            raise RuntimeError(\n                                f\"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it doesn't return void\"\n                            )\n                    else:\n                        is_void = compdef.callback_returns_void(name)\n                        if is_void is None:\n                            raise AttributeError(\n                                f\"Callback '{name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component\"\n                            )\n                        if not is_void:\n                            raise RuntimeError(\n                                f\"Callback '{name}' cannot be used with a callback decorator for an async function, as it doesn't return void\"\n                            )\n\n                def mk_callback(\n                    self: Any, callback: typing.Callable[..., Any]\n                ) -> typing.Callable[..., Any]:\n                    def invoke(*args: Any, **kwargs: Any) -> Any:\n                        return callback(self, *args, **kwargs)\n\n                    return invoke\n\n                if \"global_name\" in callback_info:\n                    self.__instance__.set_global_callback(\n                        callback_info[\"global_name\"], name, mk_callback(self, value)","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/python/slint/slint/__init__.py#L170-L206","documentation":"Raised by the @slint.callback decorator when decorating an async function with a callback name that does not exist in the compiled Slint component. callback_returns_void(name) returned None, meaning the component defines no callback with that name, so the decorator cannot wire the handler.","triggerScenarios":"Using @slint.callback(\"name\") on an async function where `name` is misspelled, was renamed in the .slint file, or is defined in a global/component other than the decorated class.","commonSituations":"Typos between Python and .slint; refactoring callback names in the UI file without updating Python handlers; expecting the decorator to auto-create the callback (it only binds existing ones); attaching to an instance callback from the wrong component class.","solutions":["Verify the callback is declared in the .slint component with exactly this name and fix any spelling mismatch.","Ensure you are decorating the correct class — a callback in an exported global must be handled with the global-aware decorator form.","Rebuild/recompile the .slint file so the component definition includes the callback, then re-run."],"exampleFix":"# before (.slint has: callback submit();) but Python says\n@slint.callback(\"on_submit\")\nasync def submit(): ...\n\n# after: names must match the .slint declaration\n@slint.callback(\"submit\")\nasync def submit(): ...","handlingStrategy":"validation","validationCode":"if comp.callback_returns_void(name) is None:\n    raise NameError(f\"callback '{name}' not declared in Slint component\")","typeGuard":null,"tryCatchPattern":"try:\n    result = slint.load_file(\"app.slint\")\nexcept slint.CompileError:\n    ...  # names mismatch usually surfaces at load/decoration time","preventionTips":["Copy-paste callback names from .slint into Python instead of retyping.","Bind callbacks right after load_file so mismatches surface early in CI."],"tags":["python","callback","async","name-resolution"],"backgroundTag":"entity-not-found","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}