{"record":{"id":"8c91f1860a9128c3","repo":"sgl-project/sglang","slug":"object-has-no-attribute","errorCode":null,"errorMessage":"'{}' object has no attribute '{}'","messagePattern":"'(.+?)' object has no attribute '(.+?)'","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/schedule_batch.py","lineNumber":265,"sourceCode":"            setattr(self, name, value)\n\n        self.validate()\n\n    def __getattr__(self, name: str) -> Any:\n        \"\"\"\n        Delegate attribute access to sampling_params if not found in Req.\n        This is only called when the attribute is not found in the instance.\n        \"\"\"\n        if name == \"sampling_params\":\n            raise AttributeError(\n                f\"'{type(self).__name__}' object has no attribute '{name}'\"\n            )\n\n        sampling_params = object.__getattribute__(self, \"sampling_params\")\n        if sampling_params is not None and hasattr(sampling_params, name):\n            return getattr(sampling_params, name)\n\n        raise AttributeError(\n            f\"'{type(self).__name__}' object has no attribute '{name}'\"\n        )\n\n    def __setattr__(self, name: str, value: Any) -> None:\n        \"\"\"\n        Smart attribute setting:\n        1. If field exists in Req, set it in Req\n        2. Else if field exists in sampling_params, set it in sampling_params\n        3. Else set it in Req (for dynamic attributes)\n        \"\"\"\n        if name == \"sampling_params\":\n            object.__setattr__(self, name, value)\n            return\n\n        if name in self.__class__.__dataclass_fields__:\n            object.__setattr__(self, name, value)\n            return\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/schedule_batch.py#L247-L283","documentation":"Generic fallback of Req.__getattr__: the attribute was not found on the Req instance, and either sampling_params is None or does not expose the attribute either, so delegation fails with a standard AttributeError naming the class and attribute.","triggerScenarios":"Accessing any req.<field> that exists neither on Req nor on its sampling_params object, e.g. req.temperature when sampling_params is None or lacks it.","commonSituations":"Field renamed between versions (e.g. sampling param moved into sampling_params only); accessing LLM-style request fields on a multimodal Req; None sampling_params during early lifecycle.","solutions":["Check the Req dataclass/sampling_params class for the correct field name","Guard with getattr(req, 'field', default) since __getattr__ integrates with hasattr","Set sampling_params before accessing delegated fields"],"exampleFix":"# before\ntop = req.top_k\n# after\ntop = getattr(req, 'top_k', 1) if req.sampling_params is not None else 1","handlingStrategy":"type-guard","validationCode":"val = getattr(req, 'top_k', None) if req.__dict__.get('sampling_params') is not None else None","typeGuard":"def req_get(req, field, default=None):\n    sp = req.__dict__.get('sampling_params')\n    return getattr(sp, field, default) if sp is not None else default","tryCatchPattern":"try:\n    v = getattr(req, field)\nexcept AttributeError:\n    v = default","preventionTips":["Use getattr(req, field, default) everywhere","Pin field names against the Req/sampling_params definitions each upgrade"],"tags":["attribute-access","req"],"backgroundTag":"attribute-missing-during-init","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}