{"record":{"id":"68b7678b67300e2c","repo":"sgl-project/sglang","slug":"resolved-target-qualified-name-is-not-callable","errorCode":null,"errorMessage":"resolved target '{qualified_name}' is not callable: {type(target)}","messagePattern":"resolved target '(.+?)' is not callable: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/debug_utils/source_patcher/code_patcher.py","lineNumber":191,"sourceCode":"    target: Any = None\n    for split_idx in range(len(parts), 0, -1):\n        module_path: str = \".\".join(parts[:split_idx])\n        try:\n            target = importlib.import_module(module_path)\n            attr_parts: list[str] = parts[split_idx:]\n            break\n        except ImportError:\n            continue\n    else:\n        raise ImportError(f\"could not import any module prefix of '{qualified_name}'\")\n\n    for attr_name in attr_parts:\n        target = getattr(target, attr_name)\n\n    if isinstance(target, classmethod):\n        target = target.__func__\n    if not callable(target):\n        raise TypeError(\n            f\"resolved target '{qualified_name}' is not callable: {type(target)}\"\n        )\n\n    return target\n","sourceCodeStart":173,"sourceCodeEnd":196,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/debug_utils/source_patcher/code_patcher.py#L173-L196","documentation":"Raised by source_patcher's _resolve_target after successfully importing the module and walking attributes, when the final resolved object is not callable. Since patching wraps/replaces functions, the target must be callable (plain functions, bound methods, or classmethod __func__ which is unwrapped just above). Resolving to a class attribute, module, or data field triggers this TypeError.","triggerScenarios":"Targeting a non-function attribute, e.g. 'pkg.mod.SOME_CONSTANT', 'pkg.mod' (the module itself), or 'pkg.mod.MyClass' where MyClass is a dataclass attribute rather than a method. Also targeting a property object or instance attribute.","commonSituations":"Patch spec points at a variable or constant instead of the function; refactoring turned a function into a plain attribute; the qualified name resolves to an intermediate module in the dotted chain (e.g. dropping the final method name).","solutions":["Make sure the qualified name ends at a function or method, not a constant/class/module","Check with callable(pkg.mod.target) in a REPL to confirm","If the symbol changed kind after a refactor, update the patch strategy — some attributes need a different patch mechanism than function wrapping"],"exampleFix":"# before\nPatchSpec(target='sglang.srt.xyz.CONFIG_FLAGS', ...)\n\n# after\nPatchSpec(target='sglang.srt.xyz.get_config_flags', ...)","handlingStrategy":"type-guard","validationCode":"mod, attr = qualified_name.rsplit('.', 1)\nimport importlib\nobj = getattr(importlib.import_module(mod), attr, None)\nif not callable(obj):\n    raise ConfigError(f'{qualified_name} resolves to non-callable {type(obj)}')","typeGuard":"def is_callable_target(qualified_name: str) -> bool:\n    import importlib\n    target = None\n    for i in range(len(qualified_name.split('.')), 0, -1):\n        try:\n            target = importlib.import_module('.'.join(qualified_name.split('.')[:i])); break\n        except ImportError:\n            continue\n    for part in qualified_name.split('.')[i:]:\n        target = getattr(target, part)\n    return callable(target)","tryCatchPattern":"try:\n    fn = _resolve_target(qualified_name)\nexcept TypeError as e:\n    if 'not callable' in str(e):\n        raise ConfigError(f'target {qualified_name} is not a function/method') from e\n    raise","preventionTips":["End patch targets at a function or method name","Confirm with callable() in a REPL when unsure","Watch for refactors that convert functions to attributes"],"tags":["patching","type-check","source-patcher","sglang"],"backgroundTag":"target-not-callable","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}