{"record":{"id":"90e6a270e0df5b0f","repo":"locustio/locust","slug":"if-you-want-to-change-the-state-of-the-request-yo","errorCode":null,"errorMessage":"If you want to change the state of the request, you must pass catch_response=True. See http://docs.locust.io/en/stable/writing-a-locustfile.html#validating-responses","messagePattern":"If you want to change the state of the request, you must pass catch_response=True\\. See http://docs\\.locust\\.io/en/stable/writing-a-locustfile\\.html#validating-responses","errorType":"exception","errorClass":"LocustError","httpStatus":null,"severity":"error","filePath":"locust/contrib/fasthttp.py","lineNumber":628,"sourceCode":"    def status_code(self) -> int:\n        \"\"\"\n        We override status_code in order to return None if no valid response was\n        returned. E.g. in the case of connection errors\n        \"\"\"\n        return self._response.get_code() if self._response is not None else 0\n\n    @property\n    def ok(self):\n        \"\"\"Returns True if :attr:`status_code` is less than 400, False if not.\"\"\"\n        return self.status_code < 400\n\n    def _content(self):\n        if self.headers is None:\n            return None\n        return super()._content()\n\n    def success(self):\n        raise LocustError(\n            \"If you want to change the state of the request, you must pass catch_response=True. See http://docs.locust.io/en/stable/writing-a-locustfile.html#validating-responses\"\n        )\n\n    def failure(self, *_args, **_kwargs):\n        raise LocustError(\n            \"If you want to change the state of the request, you must pass catch_response=True. See http://docs.locust.io/en/stable/writing-a-locustfile.html#validating-responses\"\n        )\n\n\nclass ErrorResponse(FastResponse):  # we're really just pretending to be a FastResponse\n    \"\"\"\n    This is used as a dummy response object when geventhttpclient raises an error\n    that doesn't have a real Response object attached. E.g. a socket error or similar\n    \"\"\"\n\n    headers: Headers | None = None\n    content = None\n    status_code = 0","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/contrib/fasthttp.py#L610-L646","documentation":"FastResponse.success() is intentionally stubbed to raise LocustError. Manual request state changes are only supported on responses created with catch_response=True; otherwise the method would silently do nothing, so it fails fast with a pointer to the docs.","triggerScenarios":"Calling `.success()` (or `.failure()`) on a FastResponse returned from a FastHttpSession request made without `catch_response=True`.","commonSituations":"Adding response validation to an existing FastHttpUser and forgetting the flag; copying validation code from HttpUser examples without the kwarg; helper functions marking responses unconditionally.","solutions":["Pass `catch_response=True` to the FastHttpSession request and use the with-block","Remove manual success/failure marking and rely on automatic status handling","Centralize validation in a helper that asserts catch_response was used"],"exampleFix":"// before\nresponse = self.client.get(\"/api\")\nresponse.success()  # raises\n// after\nwith self.client.get(\"/api\", catch_response=True) as response:\n    response.success()","handlingStrategy":"validation","validationCode":"def validated_get(client, url, **kw):\n    kw[\"catch_response\"] = True\n    return client.get(url, **kw)","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.warning(\"use catch_response=True: %s\", e)","preventionTips":["Always pass catch_response=True when using success()/failure() with FastHttpSession","Wrap fasthttp requests in with-blocks for validation","Keep team templates showing the correct pattern"],"tags":["locust","fasthttp","catch-response"],"backgroundTag":"catch-response-required","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}