{"record":{"id":"9f98efc33f5e3eac","repo":"locustio/locust","slug":"tried-to-set-status-on-a-request-that-has-not-yet-9f98ef","errorCode":null,"errorMessage":"Tried to set status on a request that has not yet been made. Make sure you use a with-block, like this:\n\nwith self.client.request(..., catch_response=True) as response:\n    response.success()","messagePattern":"Tried to set status on a request that has not yet been made\\. Make sure you use a with-block, like this:\n\nwith self\\.client\\.request\\(\\.\\.\\., catch_response=True\\) as response:\n    response\\.success\\(\\)","errorType":"exception","errorClass":"LocustError","httpStatus":null,"severity":"error","filePath":"locust/contrib/fasthttp.py","lineNumber":767,"sourceCode":"            self._report_request()\n\n        return True\n\n    def _report_request(self):\n        self._request_event.fire(**self.request_meta)\n\n    def success(self):\n        \"\"\"\n        Report the response as successful\n\n        Example::\n\n            with self.client.get(\"/does/not/exist\", catch_response=True) as response:\n                if response.status_code == 404:\n                    response.success()\n        \"\"\"\n        if not self._entered:\n            raise LocustError(\n                \"Tried to set status on a request that has not yet been made. Make sure you use a with-block, like this:\\n\\nwith self.client.request(..., catch_response=True) as response:\\n    response.success()\"\n            )\n        self._manual_result = True\n\n    def failure(self, exc):\n        \"\"\"\n        Report the response as a failure.\n\n        if exc is anything other than a python exception (like a string) it will\n        be wrapped inside a CatchResponseError.\n\n        Example::\n\n            with self.client.get(\"/\", catch_response=True) as response:\n                if response.content == \"\":\n                    response.failure(\"No data\")\n        \"\"\"\n        if not self._entered:","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/contrib/fasthttp.py#L749-L785","documentation":"ResponseContextManager.success() raises LocustError when the with-block was never entered (self._entered is False), meaning the request it is meant to mark has not actually been made. This guards against calling success() on a context object created outside a with statement.","triggerScenarios":"Creating a ResponseContextManager (or obtaining it indirectly) and calling response.success() without entering it via 'with', or reusing the context object after the with-block exited improperly.","commonSituations":"Storing the response context in a variable and calling success() later, misunderstanding that the with-block is required to initiate/complete the request, or refactoring that broke the with-block scope.","solutions":["Wrap the request in a with-block: with self.client.request(..., catch_response=True) as response:","Call response.success() inside the with-block body","Remove the manual success() call if the status code should decide the outcome"],"exampleFix":"// before\nresponse = self.client.get(\"/x\", catch_response=True)\nresponse.success()\n// after\nwith self.client.get(\"/x\", catch_response=True) as response:\n    response.success()","handlingStrategy":"validation","validationCode":"def safe_success(resp):\n    if getattr(resp, \"_entered\", False):\n        resp.success()\n    else:\n        raise ValueError(\"response context was never entered; use a with-block\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call success()/failure() inside the with-block body","Never store the response context for later use outside the with-block","Keep manual marking logic close to the request call"],"tags":["python","fasthttp","locust","context-manager"],"backgroundTag":"context-manager-misuse","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}