internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: locustio/locust

Issue:
FastHttpUser is stricter than HttpUser about the host attribute
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

As a followup to https://github.com/locustio/locust/issues/1222:

`FastHttpUser` has differences from `HttpUser` but is documented as a simple drop-in replacement for most cases. The fix for https://github.com/locustio/locust/issues/1222 (https://github.com/locustio/locust/pull/1227) [was intended to relax `FastHttpUser`'s host checking to be in line with `HttpUser`'s](https://github.com/locustio/locust/issues/1222#issuecomment-574736455) however there's still a major difference between them: `HttpUser` doesn't validate the host url format, only ensuring it's not `None`:

https://github.com/locustio/locust/blob/68ffae8/locust/user/users.py#L252

I don't think there's a compelling reason for these types to differ in their host checks.

I'm using locust against a websocket service where it also uses the `FastHttpUser` client: in our case we would ideally use `host` to point to a websocket url but `FastHttpUser`'s stricter check disallows this whereas `HttpUser` would.

So I think the stricter checking should be removed entirely to bring them into parity.

### Command line

locust -f locustfiles/locustfile.py  --websocket_url ws://localhost:9150

### Locustfile contents

```python3
.
```


### Python version

3.10

### Locust version

2.19.1

### Operating system

Linux


Discussion:

Resolving patch:
diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py
--- a/locust/contrib/fasthttp.py
+++ b/locust/contrib/fasthttp.py
@@ -338,8 +338,6 @@ def __init__(self, environment):
             raise LocustError(
                 "You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option."
             )
-        if not re.match(r"^https?://[^/]+", self.host, re.I):
-            raise LocustError(f"Invalid host (`{self.host}`), must be a valid base URL. E.g. http://example.com")
 
         self.client: FastHttpSession = FastHttpSession(
             self.environment,


Test patch:
Repository: locustio/locust

Issue:
FastHTTPUser determines StatusCode 304 as Failed
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

The status code is less than 400, but it is Failed.
Run the same scenario with HttpUser, 304 will not be treated as an error.

```
$ locust -f test.py --headless -u 1 -r 1 --run-time 1s
...
Error report
# occurrences      Error                                                                                               
------------------|-------------------------------------------------------------------------------------------------------------------------------------------
18                 GET /en/stable/_static/css/theme.css: BadStatusCode('https://docs.locust.io/en/stable/_static/css/theme.css', code=304)
------------------|-------------------------------------------------------------------------------------------------------------------------------------------
```

### Command line

locust -f test.py --headless -u 1 -r 1 --run-time 1s

### Locustfile contents

```python3
from locust import FastHttpUser, task


class SampleScenario(FastHttpUser):
    host = "https://docs.locust.io"
    default_headers = {
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "ja",
        "Connection": "keep-alive",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0",
        "sec-ch-ua": '"Microsoft Edge";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"',
    }

    @task
    def task_01(self):
        with self.client.get(
            url="/en/stable/_static/css/theme.css",
            headers={
                "Accept": "text/css,*/*;q=0.1",
                "If-Modified-Since": "Thu, 05 Oct 2023 21:35:33 GMT",
                "If-None-Match": 'W/"f14328d9217f8a6517a2c91eaca7764a"',
                "Referer": "https://docs.locust.io/en/stable/quickstart.html",
                "Sec-Fetch-Dest": "style",
                "Sec-Fetch-Mode": "no-cors",
                "Sec-Fetch-Site": "same-origin",
            },
            catch_response=True,
        ) as resp:
            pass
```


### Python version

3.9.18

### Locust version

2.19.1

### Operating system

Rocky Linux 9


Discussion:

Resolving patch:
diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py
--- a/locust/contrib/fasthttp.py
+++ b/locust/contrib/fasthttp.py
@@ -539,7 +539,7 @@ def raise_for_status(self):
 class LocustUserAgent(UserAgent):
     response_type = FastResponse
     request_type = FastRequest
-    valid_response_codes = frozenset([200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 301, 302, 303, 307])
+    valid_response_codes = frozenset([200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 301, 302, 303, 304, 307])
 
     def __init__(self, client_pool: Optional[HTTPClientPool] = None, **kwargs):
         super().__init__(**kwargs)


Test patch:
Repository: locustio/locust

Issue:
TaskSet missing _cp_last_run attribute
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

When using the `constant_pacing` wait time strategy in a task set, an error is thrown.
`TaskSet` instances do not have a `_cp_last_run` attribute.

```
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\P3701275\projects\20240104_TaskSetTest\venv\Lib\site-packages\locust\user\task.py", line 343, in run
    self.execute_next_task()
  File "C:\Users\P3701275\projects\20240104_TaskSetTest\venv\Lib\site-packages\locust\user\task.py", line 376, in execute_next_task
    self.execute_task(self._task_queue.pop(0))
  File "C:\Users\P3701275\projects\20240104_TaskSetTest\venv\Lib\site-packages\locust\user\task.py", line 494, in execute_task
    task(self.user).run()
  File "C:\Users\P3701275\projects\20240104_TaskSetTest\venv\Lib\site-packages\locust\user\task.py", line 371, in run
    self.wait()
  File "C:\Users\P3701275\projects\20240104_TaskSetTest\venv\Lib\site-packages\locust\user\task.py", line 449, in wait
    self._sleep(self.wait_time())
                ^^^^^^^^^^^^^^^^
  File "C:\Users\P3701275\projects\20240104_TaskSetTest\venv\Lib\site-packages\locust\user\wait_time.py", line 52, in wait_time_func
    run_time = time() - self._cp_last_run - self._cp_last_wait_time
                        ^^^^^^^^^^^^^^^^^
AttributeError: 'MyTaskSet' object has no attribute '_cp_last_run'
```

### Command line

locust -f locustfile_cp_nested.py -t 20s -H "http://www.google.com" --headless

### Locustfile contents

```python3
from locust import TaskSet, constant, task, HttpUser, constant_pacing


class MyUser(HttpUser):
    wait_time = constant(1)

    @task
    class MyTaskSet(TaskSet):
        wait_time = constant_pacing(1)

        @task
        def do_something(self):
            self.client.get("/")
```


### Python version

3.11

### Locust version

2.20.1

### Operating system

Windows


Discussion:

Resolving patch:
diff --git a/locust/user/task.py b/locust/user/task.py
--- a/locust/user/task.py
+++ b/locust/user/task.py
@@ -298,6 +298,7 @@ def __init__(self, parent: "User") -> None:
             self.max_wait = self.user.max_wait
         if not self.wait_function:
             self.wait_function = self.user.wait_function
+        self._cp_last_run = time()  # used by constant_pacing wait_time
 
     @property
     def user(self) -> "User":


Test patch:
Repository: locustio/locust

Issue:
95th percentile line chart does not display correctly on the Response Times (ms) graph
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

The 95th percentile line chart does not correctly display over time,

Every time you do a hard refresh on the Charts screen (http://mylocust.com/?tab=charts)
The 95th line starts getting render from the start of the test, and it does not show the historical values.

#### Example of refreshing the page to see the 95th line behavior
![avg_resp_time](https://github.com/locustio/locust/assets/6494108/b9b65651-8210-411c-82f1-c34c1e5a37fd)

#### The 95th percentile line shows up correctly going directly to the Locust test report
(http://mylocust.com/stats/report?theme=dark)
<img width="1135" alt="Screenshot 2024-01-10 at 11 23 50" src="https://github.com/locustio/locust/assets/6494108/9d83f39d-f338-4a1f-8a75-4f059a6c8900">


### Command line

-f my_test.py --autostart --modern-ui

### Locustfile contents

```python3
class FastUser(FastHttpUser):
    tasks = [FastUserTasks]


class FastUserTasks(TaskSet):
    @tag("Task1")
    @task(1)
    def task1(self):
        """
        I omitted how below variables are generated. Overall, there is some logic that generates protobuf messages
        that are sent as binary over http post action when executing the tasks, I have around 22 tasks that send 
        different protobuf messages.
        """
        self.client.post(
            url,
            name=f"/{message_type}",
            data=message,
            headers={
                "Content-Type": "application/octet-stream"
            }
        )
```


### Python version

3.11

### Locust version

2.20.1

### Operating system

MacOS


Discussion:
@andrewbaldwin44 Can you take a look?

Resolving patch:
diff --git a/locust/stats.py b/locust/stats.py
--- a/locust/stats.py
+++ b/locust/stats.py
@@ -925,6 +925,7 @@ def stats_history(runner: "Runner") -> None:
             }
 
             r = {
+                **current_response_time_percentiles,
                 "time": datetime.datetime.now(tz=datetime.timezone.utc).strftime("%H:%M:%S"),
                 "current_rps": stats.total.current_rps or 0,
                 "current_fail_per_sec": stats.total.current_fail_per_sec or 0,
@@ -933,7 +934,6 @@ def stats_history(runner: "Runner") -> None:
                 "response_time_percentile_2": stats.total.get_current_response_time_percentile(PERCENTILES_TO_CHART[1])
                 or 0,
                 "total_avg_response_time": stats.total.avg_response_time,
-                "current_response_time_percentiles": current_response_time_percentiles,
                 "user_count": runner.user_count or 0,
             }
             stats.history.append(r)


Test patch:
Repository: locustio/locust

Issue:
Modern UI: Average Response Time and 95th percentile have the same color
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

Average Response Time and 95th percentile have the same color.
<img width="1439" alt="image" src="https://github.com/locustio/locust/assets/1105370/0c3c5f04-7d30-4e28-859c-0fdacdcc2275">

Actually, is it possible to turn off average response time?

### Command line

-

### Locustfile contents

```python3
-
```


### Python version

3.11

### Locust version

2.23.0

### Operating system

-


Discussion:
Thanks! I knew on the old UI we used to limit the percentiles display to two, I forgot we didn't set a limit on the new UI. How does something like this look? (I will set a limit to 6 percentiles)
![image](https://github.com/locustio/locust/assets/59211596/a664d8f7-e6a6-4a83-9ad9-f532114ed6cb)

As for the average, there isn't currently a way to disable it. The reason is because `PERCENTILES_TO_CHART` only accepts integers. Most likely we would need to set a boolean or create a new argument in order to be able to disable showing the average. What do you think @cyberw? Should we have a way of disabling showing the average stat in the charts?
The suggested colors look great imo :)

I'm in no rush to add a feature to disable average.

Resolving patch:
diff --git a/locust/main.py b/locust/main.py
--- a/locust/main.py
+++ b/locust/main.py
@@ -132,6 +132,10 @@ def main():
         logging.error("stats.PERCENTILES_TO_CHART parameter should be 2 parameters \n")
         sys.exit(1)
 
+    if len(stats.MODERN_UI_PERCENTILES_TO_CHART) > 6:
+        logging.error("stats.MODERN_UI_PERCENTILES_TO_CHART parameter should be a maximum of 6 parameters \n")
+        sys.exit(1)
+
     def is_valid_percentile(parameter):
         try:
             if 0 < float(parameter) < 1:


Test patch:
Repository: locustio/locust

Issue:
`'NoneType' object has no attribute 'get'` when `stream=True` in `FastHttpSession.request`
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

I'm using the `request(..., stream=True)` in my task and occasionally, I get the following stack trace (slightly redacted):

```
'NoneType' object has no attribute 'get'
...
  File ".../locustfile.py", line XXX, in some_task
    with self.client.post("/some-path",
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 284, in post
    return self.request("POST", url, data=data, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/locust/contrib/fasthttp.py", line 236, in request
    request_meta["response_length"] = int(response.headers.get("response_length") or 0)
```

The issue happens when there's a network connectivity problem, making `response` having no `response.headers` object.

Maybe a somewhat safer approach around the code
```
if stream:
    request_meta["response_length"] = int(response.headers.get("response_length") or 0)
``` 
in `FastHttpSession.request` is necessary?


### Command line

Executed via IDE Debugger (does not matter)

### Locustfile contents

```python3
class SimpleUser(FastHttpUser):
    @task(1)
    def some_task(self):
        with self.client.post("/some-path", stream=True) as resp:
            pass
```


### Python version

3.11

### Locust version

2.24.0

### Operating system

Linux


Discussion:

Resolving patch:
diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py
--- a/locust/contrib/fasthttp.py
+++ b/locust/contrib/fasthttp.py
@@ -230,16 +230,18 @@ def request(
         if not allow_redirects:
             self.client.redirect_resonse_codes = old_redirect_response_codes
 
+        request_meta["response_length"] = 0  # default value, if length cannot be determined
+
         # get the length of the content, but if the argument stream is set to True, we take
         # the size from the content-length header, in order to not trigger fetching of the body
         if stream:
-            request_meta["response_length"] = int(response.headers.get("response_length") or 0)
+            if response.headers and "response_length" in response.headers:
+                request_meta["response_length"] = int(response.headers["response_length"])
         else:
             try:
-                request_meta["response_length"] = len(response.content or "")
+                request_meta["response_length"] = len(response.content) if response.content else 0
             except HTTPParseError as e:
                 request_meta["response_time"] = (time.perf_counter() - start_perf_counter) * 1000
-                request_meta["response_length"] = 0
                 request_meta["exception"] = e
                 self.environment.events.request.fire(**request_meta)
                 return response


Test patch:
Repository: locustio/locust

Issue:
Locust insists on using IPv6 despite being in an IPv4 stack.
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am reporting a bug, not asking a question

### Description

I have an environment that is IPv4-only, but there is an IPv6 address listed in /etc/hosts. When I try to connect to the master using the following command, it results in an error:

```
# locust -f ./p4_basic_code.py --worker --master-host locust-master -L DEBUG
[2024-04-25 06:24:31,138] ip-192-168-0-235.ap-northeast-3.compute.internal/DEBUG/locust.runners: Failed to connect to master locust-master:5557, retry 1/60.
```

By changing [self.socket.setsockopt(zmq.IPV6, 1)](https://github.com/locustio/locust/blob/master/locust/rpc/zmqrpc.py#L18) to 0 resolves the issue.
```
# cat /etc/hosts
127.0.0.1 localhost
192.168.0.235 ip-192-168-0-235.ap-northeast-3.compute.internal
127.255.0.1 locust-master
2600:f0f0:0:0:0:0:0:1 locust-master
```

I recommend detecting whether the current environment supports IPv6 before enabling it.

### Command line

locust -f ./p4_basic_code.py --worker --master-host locust-master -L DEBUG

### Locustfile contents

```python3
N/A
```


### Python version

3.11

### Locust version

2.26.0

### Operating system

Debian 12


Discussion:
Latest locust version is 2.26, start by updating. If that doesnt work, maybe you could provide a PR?
Hi, I've verified that the issue persists in the latest version `2.26.0`. I'll check if I can submit a pull request."
FYI, use version 2.20.0 as a temporary solution.

Resolving patch:
diff --git a/locust/rpc/zmqrpc.py b/locust/rpc/zmqrpc.py
--- a/locust/rpc/zmqrpc.py
+++ b/locust/rpc/zmqrpc.py
@@ -4,6 +4,7 @@
 import msgpack.exceptions as msgerr
 import zmq.error as zmqerr
 import zmq.green as zmq
+from urllib3.util.connection import HAS_IPV6
 
 from .protocol import Message
 
@@ -15,7 +16,8 @@ def __init__(self, sock_type):
 
         self.socket.setsockopt(zmq.TCP_KEEPALIVE, 1)
         self.socket.setsockopt(zmq.TCP_KEEPALIVE_IDLE, 30)
-        self.socket.setsockopt(zmq.IPV6, 1)
+        if HAS_IPV6:
+            self.socket.setsockopt(zmq.IPV6, 1)
 
     @retry()
     def send(self, msg):


Test patch:
Repository: locustio/locust

Issue:
Log a warning if getting locustfile from master takes more than 60s
### Prerequisites

- [X] I am using [the latest version of Locust](https://github.com/locustio/locust/releases/)
- [X] I am suggesting a new feature, not asking a question

### Description

https://github.com/locustio/locust/blob/1cf4f337bc19671661d3b2e2538efe75f2d64b22/locust/argument_parser.py#L250


Discussion:

Resolving patch:
diff --git a/locust/argument_parser.py b/locust/argument_parser.py
--- a/locust/argument_parser.py
+++ b/locust/argument_parser.py
@@ -241,10 +241,18 @@ def ask_for_locustfile():
             tempclient.send(Message("locustfile", None, client_id))
             gevent.sleep(1)
 
+    def log_warning():
+        gevent.sleep(10)
+        while not got_reply:
+            sys.stderr.write("Waiting to connect to master to receive locustfile...\n")
+            gevent.sleep(60)
+
     def wait_for_reply():
         return tempclient.recv()
 
     gevent.spawn(ask_for_locustfile)
+    gevent.spawn(log_warning)
+
     try:
         # wait same time as for client_ready ack. not that it is really relevant...
         msg = gevent.spawn(wait_for_reply).get(timeout=runners.CONNECT_TIMEOUT * runners.CONNECT_RETRY_COUNT)


Test patch:
Repository: superduper-io/superduper

Issue:
[BUG]: Variable inject for list values in a serialised component missing kwargs
c = Component()

c.dict() -> {some keys: [ {}, { 'v': Variable_type }] }

due to 
```

def _replace_variables(x, db, **kwargs):
    from .document import Document

    if isinstance(x, dict):
        return {
            _replace_variables(k, db, **kwargs): _replace_variables(v, db, **kwargs)
            for k, v in x.items()
        }
    if isinstance(x, (list, tuple)):
        return [_replace_variables(v, db) for v in x] -> BUG (need **kwargs here)
    if isinstance(x, Variable):
        return x.set(db, **kwargs)
    if isinstance(x, Document):
        return x.set_variables(db, **kwargs)
    return x

```


Discussion:

Resolving patch:
diff --git a/superduperdb/base/serializable.py b/superduperdb/base/serializable.py
--- a/superduperdb/base/serializable.py
+++ b/superduperdb/base/serializable.py
@@ -56,7 +56,7 @@ def _replace_variables(x, db, **kwargs):
             for k, v in x.items()
         }
     if isinstance(x, (list, tuple)):
-        return [_replace_variables(v, db) for v in x]
+        return [_replace_variables(v, db, **kwargs) for v in x]
     if isinstance(x, Variable):
         return x.set(db, **kwargs)
     if isinstance(x, Document):


Test patch:
Repository: superduper-io/superduper

Issue:
[BUG]: Compatible listener in VectorIndex gets select = None, which causes refresh job to crash
if a Listener has select = None,
and we add this listener to db.

when we execute a query and refresh job gets triggered 
we are building a taskworkflow in refresh_after_insert 
```
 Document.decode(info['dict']['select'], None)
```
This causes an error.
https://github.com/SuperDuperDB/superduperdb/blob/9c336cb13e4ffb8ae38ae3cda88c261825f38e4a/superduperdb/base/datalayer.py#L708


Discussion:

Resolving patch:
diff --git a/superduperdb/base/datalayer.py b/superduperdb/base/datalayer.py
--- a/superduperdb/base/datalayer.py
+++ b/superduperdb/base/datalayer.py
@@ -704,7 +704,15 @@ def _build_task_workflow(
         for identifier in listeners:
             # TODO reload listener here (with lazy loading)
             info = self.metadata.get_component('listener', identifier)
-            listener_query = Document.decode(info['dict']['select'], None)
+            select = info['dict']['select']
+            if not select:
+                logging.debug(
+                    f'Listener {identifier} was loaded with `None` select, '
+                    f'{identifier} will not be added to refresh jobs.'
+                )
+                continue
+
+            listener_query = Document.decode(select, None)
             listener_select = serializable.Serializable.decode(listener_query)
             listener_selects.update({identifier: listener_select})
             if listener_select is None:
@@ -733,7 +741,7 @@ def _build_task_workflow(
             )
 
         for identifier in listeners:
-            listener_select = listener_selects[identifier]
+            listener_select = listener_selects.get(identifier, None)
             if listener_select is None:
                 continue
             if (


Test patch: