{"record":{"id":"21f547af54edbe3c","repo":"sgl-project/sglang","slug":"req-object-has-no-attribute-sampling-params","errorCode":null,"errorMessage":"'Req' object has no attribute 'sampling_params'","messagePattern":"'Req' object has no attribute 'sampling_params'","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/schedule_batch.py","lineNumber":257,"sourceCode":"            if name in kwargs:\n                object.__setattr__(self, name, kwargs.pop(name))\n            elif field.default is not MISSING:\n                object.__setattr__(self, name, field.default)\n            elif field.default_factory is not MISSING:\n                object.__setattr__(self, name, field.default_factory())\n\n        for name, value in kwargs.items():\n            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        \"\"\"","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/schedule_batch.py#L239-L275","documentation":"Req implements __getattr__ delegating unknown attributes to self.sampling_params. When 'sampling_params' itself is missing (never set, e.g. during __init__ before assignment), the delegation guard raises this AttributeError to prevent infinite recursion.","triggerScenarios":"Accessing req.sampling_params before the attribute was assigned in Req.__init__, or on a Req constructed via __new__/pickle that skipped __init__.","commonSituations":"Deserializing Req objects (deepcopy/pickle for DP broadcast) that drop instance attrs; accessing fields in code paths that run before init completes; bugs where attribute name 'sampling_param' is misspelled.","solutions":["Ensure Req.__init__ always assigns sampling_params (even None) before any attribute access","For pickled/deepcopied reqs, restore attributes in __setstate__/__deepcopy__","Access fields via req.sampling_params.<field> with an explicit None check"],"exampleFix":"# before\nparams = req.sampling_params  # before init finished\n# after\nparams = object.__getattribute__(req, 'sampling_params', ) if hasattr(req, 'sampling_params') else None","handlingStrategy":"try-catch","validationCode":"has_sp = 'sampling_params' in req.__dict__\nparams = req.__dict__.get('sampling_params') if has_sp else None","typeGuard":"def has_sampling_params(req) -> bool:\n    return 'sampling_params' in getattr(req, '__dict__', {})","tryCatchPattern":"try:\n    v = req.sampling_params\nexcept AttributeError:\n    v = None","preventionTips":["Always construct Req through its __init__","Implement __setstate__ to restore sampling_params after pickling"],"tags":["attribute-access","req","serialization"],"backgroundTag":"attribute-missing-during-init","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}