locustio/locust · error · LocustError

Tried to set status on a request that has not yet been made.

Error message

Tried to set status on a request that has not yet been made. Make sure you use a with-block, like this:

with self.client.request(..., catch_response=True) as response:
    response.success()

What it means

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.

Source

Thrown at locust/clients.py:454

            self.url = orig_url

        return True

    def _report_request(self, exc=None):
        self._request_event.fire(**self.request_meta)

    def success(self):
        """
        Report the response as successful

        Example::

            with self.client.get("/does/not/exist", catch_response=True) as response:
                if response.status_code == 404:
                    response.success()
        """
        if not self._entered:
            raise LocustError(
                "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()"
            )
        self._manual_result = True

    def failure(self, exc):
        """
        Report the response as a failure.

        if exc is anything other than a python exception (like a string) it will
        be wrapped inside a CatchResponseError.

        Example::

            with self.client.get("/", catch_response=True) as response:
                if response.content == b"":
                    response.failure("No data")
        """
        if not self._entered:

View on GitHub (pinned to f391a716e1)

Solutions

  1. Wrap the request in a with-block: `with self.client.request(..., catch_response=True) as response: response.success()`
  2. Only call success()/failure() inside the with-block body
  3. If you don't need manual status, remove the success() call and let Locust mark the request automatically

Example fix

// before
response = self.client.get("/does/not/exist", catch_response=True)
if response.status_code == 404:
    response.success()
// after
with self.client.get("/does/not/exist", catch_response=True) as response:
    if response.status_code == 404:
        response.success()
Defensive patterns

Strategy: validation

Validate before calling

assert resp._entered, "call success() inside the with-block"

Type guard

null

Try / catch

with self.client.get(url, catch_response=True) as resp:
    try:
        resp.success()
    except LocustError as e:
        logger.error(e)

Prevention

When it happens

Trigger: 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.

Common situations: Refactoring from `resp = self.client.get(url, catch_response=True); resp.success()` style code; calling success() outside the with scope on a saved reference.

Related errors


AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29). Data as JSON: /api/errors/37716ff446e6e780. Report an issue: GitHub.