sgl-project/sglang · error · TypeError

resolved target '{qualified_name}' is not callable: {type(ta

Error message

resolved target '{qualified_name}' is not callable: {type(target)}

What it means

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.

Source

Thrown at python/sglang/srt/debug_utils/source_patcher/code_patcher.py:191

    target: Any = None
    for split_idx in range(len(parts), 0, -1):
        module_path: str = ".".join(parts[:split_idx])
        try:
            target = importlib.import_module(module_path)
            attr_parts: list[str] = parts[split_idx:]
            break
        except ImportError:
            continue
    else:
        raise ImportError(f"could not import any module prefix of '{qualified_name}'")

    for attr_name in attr_parts:
        target = getattr(target, attr_name)

    if isinstance(target, classmethod):
        target = target.__func__
    if not callable(target):
        raise TypeError(
            f"resolved target '{qualified_name}' is not callable: {type(target)}"
        )

    return target

View on GitHub (pinned to 0132848349)

Solutions

  1. Make sure the qualified name ends at a function or method, not a constant/class/module
  2. Check with callable(pkg.mod.target) in a REPL to confirm
  3. If the symbol changed kind after a refactor, update the patch strategy — some attributes need a different patch mechanism than function wrapping

Example fix

# before
PatchSpec(target='sglang.srt.xyz.CONFIG_FLAGS', ...)

# after
PatchSpec(target='sglang.srt.xyz.get_config_flags', ...)
Defensive patterns

Strategy: type-guard

Validate before calling

mod, attr = qualified_name.rsplit('.', 1)
import importlib
obj = getattr(importlib.import_module(mod), attr, None)
if not callable(obj):
    raise ConfigError(f'{qualified_name} resolves to non-callable {type(obj)}')

Type guard

def is_callable_target(qualified_name: str) -> bool:
    import importlib
    target = None
    for i in range(len(qualified_name.split('.')), 0, -1):
        try:
            target = importlib.import_module('.'.join(qualified_name.split('.')[:i])); break
        except ImportError:
            continue
    for part in qualified_name.split('.')[i:]:
        target = getattr(target, part)
    return callable(target)

Try / catch

try:
    fn = _resolve_target(qualified_name)
except TypeError as e:
    if 'not callable' in str(e):
        raise ConfigError(f'target {qualified_name} is not a function/method') from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/68b7678b67300e2c. Report an issue: GitHub.