{"record":{"id":"37716ff446e6e780","repo":"locustio/locust","slug":"tried-to-set-status-on-a-request-that-has-not-yet","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/clients.py","lineNumber":454,"sourceCode":"            self.url = orig_url\n\n        return True\n\n    def _report_request(self, exc=None):\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 == b\"\":\n                    response.failure(\"No data\")\n        \"\"\"\n        if not self._entered:","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/clients.py#L436-L472","documentation":"Response.success() may only be called on a catch_response-style Response that has been entered via a with-block (which sets _entered=True and performs the request). Calling it on a request that has not yet been made raises this LocustError. It guards against marking results for requests that never executed.","triggerScenarios":"Storing the result of `self.client.request(..., catch_response=True)` without a with-block and later calling `.success()` on it; calling success() before the with-block body runs.","commonSituations":"Refactoring from `resp = self.client.get(url, catch_response=True); resp.success()` style code; calling success() outside the with scope on a saved reference.","solutions":["Wrap the request in a with-block: `with self.client.request(..., catch_response=True) as response: response.success()`","Only call success()/failure() inside the with-block body","If you don't need manual status, remove the success() call and let Locust mark the request automatically"],"exampleFix":"// before\nresponse = self.client.get(\"/does/not/exist\", catch_response=True)\nif response.status_code == 404:\n    response.success()\n// after\nwith self.client.get(\"/does/not/exist\", catch_response=True) as response:\n    if response.status_code == 404:\n        response.success()","handlingStrategy":"validation","validationCode":"assert resp._entered, \"call success() inside the with-block\"","typeGuard":"null","tryCatchPattern":"with self.client.get(url, catch_response=True) as resp:\n    try:\n        resp.success()\n    except LocustError as e:\n        logger.error(e)","preventionTips":["Only call success()/failure() inside the with-block body","Never store the Response for later marking","Search codebase for `.success()` calls not indented inside a with-block"],"tags":["locust","http","catch-response","lifecycle"],"backgroundTag":"response-status-before-request","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}