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

Issue:
Graph name attribute for `complete_bipartite_graph` verbose for non-integer intputs
The `complete_bipartite_graph` creation function adds a `.graph["name"]` attribute like so:

https://github.com/networkx/networkx/blob/cca1a715217a102b970800c43a066dd759ece92d/networkx/algorithms/bipartite/generators.py#L65

This works fine when `n1` and `n2` are integers, but can get ugly when they aren't. For example:

```python
# Generator expressions designed to be intentionally verbose
>>> n = (i for i in range(4))
>>> m = (i for i in range(4, 7))
>>> G = nx.complete_bipartite_graph(n, m)
>>> print(G)
Graph named 'complete_bipartite_graph(<generator object <genexpr> at 0x7e94bc447370>, <generator object <genexpr> at 0x7e94bc5352f0>)' with 7 nodes and 12 edges
```


Discussion:
The expected behavior should be printing the length of the generator, right ?  
> The expected behavior should be printing the length of the generator, right ?

Usually it's `Graph with 7 nodes and 12 edges`

> Usually it's `Graph with 7 nodes and 12 edges`

This is a bipartite graph, so i guess n1 and n2 refers to the two  node sets.
I think it should be 
`complete_bipartite_graph(4,3) with 7 nodes and 12 edges`  

Resolving patch:
diff --git a/networkx/algorithms/bipartite/generators.py b/networkx/algorithms/bipartite/generators.py
--- a/networkx/algorithms/bipartite/generators.py
+++ b/networkx/algorithms/bipartite/generators.py
@@ -62,7 +62,7 @@ def complete_bipartite_graph(n1, n2, create_using=None):
     if len(G) != len(top) + len(bottom):
         raise nx.NetworkXError("Inputs n1 and n2 must contain distinct nodes")
     G.add_edges_from((u, v) for u in top for v in bottom)
-    G.graph["name"] = f"complete_bipartite_graph({n1}, {n2})"
+    G.graph["name"] = f"complete_bipartite_graph({len(top)}, {len(bottom)})"
     return G
 
 


Test patch:
diff --git a/networkx/algorithms/bipartite/tests/test_generators.py b/networkx/algorithms/bipartite/tests/test_generators.py
--- a/networkx/algorithms/bipartite/tests/test_generators.py
+++ b/networkx/algorithms/bipartite/tests/test_generators.py
@@ -398,3 +398,12 @@ def test_gnmk_random_graph_complete(self):
         assert set(range(n)) == X
         assert set(range(n, n + m)) == Y
         assert edges == len(list(G.edges()))
+
+    @pytest.mark.parametrize("n", (4, range(4), {0, 1, 2, 3}))
+    @pytest.mark.parametrize("m", (range(4, 7), {4, 5, 6}))
+    def test_complete_bipartite_graph_str(self, n, m):
+        """Ensure G.name is consistent for all inputs accepted by nodes_or_number.
+        See gh-7396"""
+        G = nx.complete_bipartite_graph(n, m)
+        ans = "Graph named 'complete_bipartite_graph(4, 3)' with 7 nodes and 12 edges"
+        assert str(G) == ans
Repository: networkx/networkx

Issue:
Can't replicate directed functionality of deprecated `random_tree`
The deprecated `random_tree` function supported the `create_using` kwarg to allow the creation of directed trees:

```python
>>> G = nx.random_tree(10, create_using=nx.DiGraph, seed=42)
>>> G.edges
OutEdgeView([(0, 6), (0, 4), (1, 5), (1, 8), (2, 1), (3, 7), (3, 2), (4, 3), (8, 9)])
```

The `random_labeled_tree` function is the recommended replacement for the deprecated `random_tree` fn, but it doesn't support the `create_using` kwarg. AFAICT, the only way to replicate the current behavior of `random_tree` is to create a DiGraph from the generated edges manually:

```python
>>> H = nx.random_labeled_tree(10, seed=42)  # Undirected
>>> DH = nx.DiGraph()
>>> DH.add_edges_from(H)
```

I'm mostly just raising for visibility - I don't recall if this was an explicit decision to remove `create_using` support - @vigna . From a user perspective it'd be convenient to be able to replicate existing functionality with as little code modification as possible.


Discussion:
https://github.com/networkx/networkx/pull/6758#issuecomment-1901097730


Resolving patch:
diff --git a/networkx/generators/trees.py b/networkx/generators/trees.py
--- a/networkx/generators/trees.py
+++ b/networkx/generators/trees.py
@@ -452,6 +452,24 @@ def random_labeled_tree(n, *, seed=None):
     ------
     NetworkXPointlessConcept
         If `n` is zero (because the null graph is not a tree).
+
+    Examples
+    --------
+    >>> G = nx.random_labeled_tree(5, seed=42)
+    >>> nx.is_tree(G)
+    True
+    >>> G.edges
+    EdgeView([(0, 1), (0, 3), (0, 2), (2, 4)])
+
+    A tree with *arbitrarily directed* edges can be created by assigning
+    generated edges to a ``DiGraph``:
+
+    >>> DG = nx.DiGraph()
+    >>> DG.add_edges_from(G.edges)
+    >>> nx.is_tree(DG)
+    True
+    >>> DG.edges
+    OutEdgeView([(0, 1), (0, 3), (0, 2), (2, 4)])
     """
     # Cannot create a Prüfer sequence unless `n` is at least two.
     if n == 0:


Test patch:
Repository: networkx/networkx

Issue:
`shortest_path_length()` specifies return value of `int` but was `float`
### Current Behavior

if `shortest_path_length` is used with weights containing `float`, a `float` is returned, contrary to the function docs.

```python
import networkx as nx

G = nx.DiGraph()

G.add_node(0)
G.add_node(1)
G.add_node(2)

G.add_edge(0, 1, weight=3.33333)
G.add_edge(1, 2, weight=4.75555)

length = nx.shortest_path_length(G, source=0, target=2, weight='weight', method='dijkstra')
print(length)
print(type(length))
```

```
8.08888
<class 'float'>
```

### Expected Behavior

According to the documentation I would expect an integer or a `ValueError`, as it specifies that an `int` is returned -- see [docs](https://networkx.org/documentation/stable/_modules/networkx/algorithms/shortest_paths/generic.html#shortest_path_length) and [code](https://github.com/networkx/networkx/blob/729bec23b10e89b5f6d37175e30484f2278107c4/networkx/algorithms/shortest_paths/generic.py#L225-L229)

however, the underlying function used here, `dijkstra_path_length`, [specifies](https://github.com/networkx/networkx/blob/729bec23b10e89b5f6d37175e30484f2278107c4/networkx/algorithms/shortest_paths/weighted.py#L205-L208) that a "number" is returned.

Perhaps this is a documentation bug? Are float in edge weights supported (with the caveat of floating point issues)?

### Steps to Reproduce

see above

### Environment

Python version: Python 3.12.3
NetworkX version: 3.3




Discussion:
Thanks for this!  The docs are indeed incorrect here. It should return a number or iterator, not specifically an `int` or iterator.  It goes all the way back to #744 before which it is correctly called a number.  

NetworkX supports `float` edge weights with the usual caveats of floating point issues.
Thanks!
  Hi @dschult,

I'm new to this project and would love to contribute to this issue. I'm interested in working on this issue. Is it still available? ,Could you provide some guidance on how to get started?

Thanks!

We dont assign issues to individual developers -- you can start looking at an issue. When you have a solution open a PR. Or open a PR with a partial solution and we'll give feedback. (actually we'll give feedback either way. :)

This one might be a good one to start with. To start, you should read through the developer section of the docs, especially the contributor guide.

Resolving patch:
diff --git a/networkx/algorithms/shortest_paths/generic.py b/networkx/algorithms/shortest_paths/generic.py
--- a/networkx/algorithms/shortest_paths/generic.py
+++ b/networkx/algorithms/shortest_paths/generic.py
@@ -224,7 +224,7 @@ def shortest_path_length(G, source=None, target=None, weight=None, method="dijks
 
     Returns
     -------
-    length: int or iterator
+    length: number or iterator
         If the source and target are both specified, return the length of
         the shortest path from the source to the target.
 


Test patch:
Repository: uclapi/uclapi

Issue:
Error responses missing OK property and correct HTTP Status Code
Hello there,
when making an invalid request, say,  an invalid token, an error is given but the HTTP code is still `200 OK` when it should give an authentication error (a `400 Bad Request` or even a `401 Unauthorized`).

Request:
```http
GET /roombookings/rooms?token=uclapi-5d58c3c4e6bf9c-c2910ad3b6e054-7ef60f44f1c14f-a05147bfd17fdb HTTP/1.1
Host: uclapi.com
User-Agent: Paw/3.0.16 (Macintosh; OS X/10.12.4) NSURLConnection/1349.63
Cookie: AWSALB=8q9+FZmk9TOAZ/GG2tFsVUuckVO8STONoiGDn6/jd9FBEwFi5Ke/kvz+hIjdCmAwtpOIXGlnudL7LU3AaVxKt1sHWYGjLJnoMypHqu53r7Ub4b73trfiMx5NMVZ6
```

Response:
```http
HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Allow: GET, OPTIONS
Server: nginx/1.11.10
Set-Cookie: AWSALB=U2qTk7k+LrfxXibfskgPN1RoWvDQqKhaSBmgvUMOa3AcYgag1BZMcyz+5h5rQ2qhQc+Cm2PYzfjKV466PHcc9dleZHkLYE5O8d5q2WO+7WVbQT6VQMSSSHpOh3xy; Expires=Sat, 11 Mar 2017 14:18:40 GMT; Path=/
Transfer-Encoding: Identity
Date: Sat, 04 Mar 2017 14:18:40 GMT
X-Frame-Options: SAMEORIGIN
Vary: Accept, Cookie

{"error": "Token does not exist"}
```

Furthermore, when a request is successful, the first property is an `"ok": true`, however, with invalid requests, the `"ok": false` is missing from the error response.

Actual:
```json
{
  "error": "Token does not exist"
}
```

Expected:
```json
{
  "ok": false,
  "error": "Token does not exist"
}
```


Discussion:

Resolving patch:
diff --git a/backend/uclapi/roombookings/token_auth.py b/backend/uclapi/roombookings/token_auth.py
--- a/backend/uclapi/roombookings/token_auth.py
+++ b/backend/uclapi/roombookings/token_auth.py
@@ -1,4 +1,3 @@
-from rest_framework.response import Response
 from dashboard.models import App
 from django.core.exceptions import ObjectDoesNotExist
 from django.http import JsonResponse
@@ -9,16 +8,22 @@ def wrapped(request, *args, **kwargs):
         token = request.GET.get("token")
 
         if not token:
-            return JsonResponse({
+            response = JsonResponse({
+                "ok": False,
                 "error": "No token provided"
             })
+            response.status_code = 400
+            return response
 
         try:
             App.objects.get(api_token=token)
         except ObjectDoesNotExist:
-            return JsonResponse({
+            response = JsonResponse({
+                "ok": False,
                 "error": "Token does not exist"
             })
+            response.status_code = 400
+            return response
 
         return view_func(request, *args, **kwargs)
     return wrapped


Test patch:
Repository: uclapi/uclapi

Issue:
[Bug] Search People should return HTTP status 400 when query is missing
Currently, the `/search/people` returns a HTTP 200 code when even for an incorrect API request. For example, if you leave out the `query` param it returns the following body:

```json
{ "error": "No query provided", "ok": false}
```

Yet, the HTTP status code is 200, while it should be 400.



Discussion:

Resolving patch:
diff --git a/backend/uclapi/search/views.py b/backend/uclapi/search/views.py
--- a/backend/uclapi/search/views.py
+++ b/backend/uclapi/search/views.py
@@ -13,10 +13,12 @@
 @log_api_call
 def people(request):
     if "query" not in request.GET:
-        return JsonResponse({
+        response = JsonResponse({
             "ok": False,
-            "error": "No query provided"
+            "error": "No query provided."
         })
+        response.status_code = 400
+        return response
 
     query = request.GET["query"]
 


Test patch:
Repository: uclapi/uclapi

Issue:
[Documentation] Docs link is Absolute, not Relative
The documentation link always goes to `https://uclapi.com/docs`, even if running in, for example, staging. Just linking to `/docs` would be adequate to fix this.


Discussion:

Resolving patch:
diff --git a/backend/uclapi/resources/views.py b/backend/uclapi/resources/views.py
--- a/backend/uclapi/resources/views.py
+++ b/backend/uclapi/resources/views.py
@@ -45,7 +45,7 @@ def get_pc_availability(request, *args, **kwargs):
                 "longitude": _("longitude"),
                 "building_name": _("buildingName"),
                 "address": _("buildingAddress"),
-                "postcode": _("buildingPostCode")
+                "postcode": _("buildingPostcode")
             },
             "free_seats": _("free"),
             "total_seats": _("seats"),


Test patch:
Repository: uclapi/uclapi

Issue:
timetable/data/departments endpoint returns 500 error
The timetable/data/departments endpoint is currently returning a 500 error on any request.

I know it's not a documented endpoint, but it would be nice if it worked :)

It looks to me like the problem is line 85 below - `rate_limiting_data` is being passed as an argument to `append`. 

https://github.com/uclapi/uclapi/blob/cfd6753ae3d979bbe53573dad68babc2de19e04d/backend/uclapi/timetable/views.py#L82-L85

Removing that and replacing with this:
```python
depts["departments"].append({ 
"department_id": dept.deptid, 
"name": dept.name}) 
```
should fix it, though I don't have the whole API setup installed, so I can't be sure.


Discussion:
Sorry, just saw this! That looks right to me.

We should have this endpoint documented at some point (I think I actually wrote it up before; some of my work got lost when we moved to a new docs setup).

Resolving patch:
diff --git a/backend/uclapi/timetable/views.py b/backend/uclapi/timetable/views.py
--- a/backend/uclapi/timetable/views.py
+++ b/backend/uclapi/timetable/views.py
@@ -82,7 +82,7 @@ def get_departments(request, *args, **kwargs):
         depts["departments"].append({
             "department_id": dept.deptid,
             "name": dept.name
-        }, rate_limiting_data=kwargs)
+        })
     return JsonResponse(depts, rate_limiting_data=kwargs)
 
 


Test patch:
Repository: uclapi/uclapi

Issue:
/oauth/token Should Accept POST Requests
Many OAuth 2.0 libraries seem to expect the `/oauth/token` endpoint to accept a POST request instead of a GET one. We should probably support this too if the RFC expects it.


Discussion:
https://ucl-assistant-auth.glitch.me

Updated this code to send a URL-encoded POST request instead of a GET request. Server returns CSRF error. Found the cause of my problems earlier! 😁 
@mbellgb thank you so much for investigating this for us! I'll see if I can code up a quick solution to this now and get it into Staging. Would you might testing if I can?

Resolving patch:
diff --git a/backend/uclapi/oauth/views.py b/backend/uclapi/oauth/views.py
--- a/backend/uclapi/oauth/views.py
+++ b/backend/uclapi/oauth/views.py
@@ -20,7 +20,7 @@
 from .scoping import Scopes
 
 from uclapi.settings import REDIS_UCLAPI_HOST
-from common.decorators import uclapi_protected_endpoint
+from common.decorators import uclapi_protected_endpoint, get_var
 
 
 # The endpoint that creates a Shibboleth login and redirects the user to it
@@ -321,12 +321,13 @@ def userallow(request):
     )
 
 
+@csrf_exempt
 def token(request):
-    try:
-        code = request.GET["code"]
-        client_id = request.GET["client_id"]
-        client_secret = request.GET["client_secret"]
-    except KeyError:
+    code = get_var(request, "code")
+    client_id = get_var(request, "client_id")
+    client_secret = get_var(request, "client_secret")
+
+    if not code or not client_id or not client_secret:
         response = PrettyJsonResponse({
             "ok": False,
             "error": ("The client did not provide"


Test patch:
Repository: uclapi/uclapi

Issue:
Workspaces summary endpoint provides survey and map ids as strings rather than integers
Example response:

```json
    "ok": true,
    "surveys": [
        {
            "id": "46",
            "name": "UCL Institute of Education Library",
            "maps": [
                {
                    "id": "73",
                    "name": "Level 3",
                    "sensors_absent": 70,
                    "sensors_occupied": 87,
                    "sensors_other": 0
                },
                {
                    "id": "74",
                    "name": "Level 4",
                    "sensors_absent": 51,
                    "sensors_occupied": 45,
                    "sensors_other": 0
                },
                {
                    "id": "75",
                    "name": "Level 5",
                    "sensors_absent": 30,
                    "sensors_occupied": 41,
                    "sensors_other": 2
                }
            ]
        }
    ]
}
```

Also, there's a discrepancy in the [docs](https://uclapi.com/docs#workspaces/sensors/summary) as to the type of the id value.


Discussion:
Thanks so much for finding this! It's a regression from #365, woops!

Resolving patch:
diff --git a/backend/uclapi/workspaces/occupeye/cache.py b/backend/uclapi/workspaces/occupeye/cache.py
--- a/backend/uclapi/workspaces/occupeye/cache.py
+++ b/backend/uclapi/workspaces/occupeye/cache.py
@@ -394,7 +394,7 @@ def cache_common_summaries(self):
                 self._const.SURVEY_DATA_KEY.format(survey_id)
             )
             survey_data = {
-                "id": survey_id,
+                "id": int(survey_id),
                 "name": survey_redis_data["name"],
                 "maps": []
             }
@@ -402,7 +402,7 @@ def cache_common_summaries(self):
             sensors = api.get_survey_sensors(survey_id)
             for survey_map in sensors["maps"]:
                 map_data = {
-                    "id": survey_map["id"],
+                    "id": int(survey_map["id"]),
                     "name": survey_map["name"],
                     "sensors_absent": 0,
                     "sensors_occupied": 0,


Test patch:
Repository: uclapi/uclapi

Issue:
Move to WebPack
Building the frontend is annoying, and updating dependencies in a way that lets us test the updates is nothing short of tedious.

WebPack with proper bounds on the minor version of each component and dependency should help us stay in line and keep up to date with the frontend code.


Discussion:

Resolving patch:
diff --git a/backend/uclapi/uclapi/settings.py b/backend/uclapi/uclapi/settings.py
--- a/backend/uclapi/uclapi/settings.py
+++ b/backend/uclapi/uclapi/settings.py
@@ -187,15 +187,11 @@
 
 USE_TZ = False
 
-
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/1.10/howto/static-files/
 
 STATIC_URL = '/static/'
 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
-STATICFILES_DIRS = [
-    os.path.join(BASE_DIR, "images"),
-]
 
 # Cross Origin settings
 CORS_ORIGIN_ALLOW_ALL = True


Test patch:
Repository: uclapi/uclapi

Issue:
Remove opbeat
Opbeat is no longer a thing, so we should remove it and replace it with something else? Maybe double down on Sentry and integrate that more tightly

https://github.com/uclapi/uclapi/blob/81b90305f9316b020664b32c2436e27ab957e8a7/backend/uclapi/requirements.txt#L33


Discussion:
I was literally about to come to this issues page to open the exact same issue. BRAIN SYNC.

Resolving patch:
diff --git a/backend/uclapi/uclapi/celery.py b/backend/uclapi/uclapi/celery.py
--- a/backend/uclapi/uclapi/celery.py
+++ b/backend/uclapi/uclapi/celery.py
@@ -27,23 +27,6 @@ def on_configure(self):
 
 app.config_from_object('django.conf.settings', namespace='CELERY')
 
-
-from opbeat.contrib.django.models import \
-    register_handlers as opbeat_register_handlers, \
-    logger as opbeat_logger  # noqa: E402#
-
-from opbeat.contrib.celery import \
-    register_signal as opbeat_register_signal  # noqa: E402
-
-
-try:
-    opbeat_register_signal(app)
-except Exception as e:
-    opbeat_logger.exception('Failed installing celery hook: %s' % e)
-
-if 'opbeat.contrib.django' in settings.INSTALLED_APPS:
-    opbeat_register_handlers()
-
 app.autodiscover_tasks()
 
 
diff --git a/backend/uclapi/uclapi/settings.py b/backend/uclapi/uclapi/settings.py
--- a/backend/uclapi/uclapi/settings.py
+++ b/backend/uclapi/uclapi/settings.py
@@ -66,14 +66,12 @@
     'oauth',
     'timetable',
     'common',
-    'opbeat.contrib.django',
     'raven.contrib.django.raven_compat',
     'corsheaders',
     'workspaces'
 ]
 
 MIDDLEWARE = [
-    'opbeat.contrib.django.middleware.OpbeatAPMMiddleware',
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'corsheaders.middleware.CorsMiddleware',
@@ -143,13 +141,6 @@
 
 DATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']
 
-# analytics
-OPBEAT = {
-    'ORGANIZATION_ID': os.environ.get("OPBEAT_ORG_ID"),
-    'APP_ID': os.environ.get("OPBEAT_APP_ID"),
-    'SECRET_TOKEN': os.environ.get("OPBEAT_SECRET_TOKEN")
-}
-
 RAVEN_CONFIG = {
     'dsn': os.environ.get("SENTRY_DSN"),
 }


Test patch:
Repository: uclapi/uclapi

Issue:
AMP Doesn't Return STUDENT_TYPE
I am an idiot.

https://github.com/uclapi/uclapi/blob/69f0d3240d8ec6cf2a3b018897dc247aa58cb1bf/backend/uclapi/timetable/amp.py#L31


Discussion:

Resolving patch:
diff --git a/backend/uclapi/timetable/amp.py b/backend/uclapi/timetable/amp.py
--- a/backend/uclapi/timetable/amp.py
+++ b/backend/uclapi/timetable/amp.py
@@ -31,7 +31,8 @@ def __init__(self, delivery_code):
     def get_delivery(self):
         return {
             "fheq_level": self.fheq_level,
-            "is_undergraduate": self.undergraduate
+            "is_undergraduate": self.undergraduate,
+            "student_type": self.student_type
         }
 
 


Test patch:
Repository: uclapi/uclapi

Issue:
Scaling of PostgreSQL Connections
We have tried in the past to implement connection pooling for Django <==> PostgreSQL. We should try this again so that the system doesn't get pulled down by too many parallel requests (as could happen in the event of UCL Assistant).


Discussion:
can we implement https://pypi.org/project/django-postgrespool2/0.2.0/?

Resolving patch:
diff --git a/backend/uclapi/uclapi/settings.py b/backend/uclapi/uclapi/settings.py
--- a/backend/uclapi/uclapi/settings.py
+++ b/backend/uclapi/uclapi/settings.py
@@ -115,7 +115,7 @@
 
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.postgresql',
+        'ENGINE': 'django_postgrespool2',
         'NAME': os.environ.get("DB_UCLAPI_NAME"),
         'USER': os.environ.get("DB_UCLAPI_USERNAME"),
         'PASSWORD': os.environ.get("DB_UCLAPI_PASSWORD"),
@@ -131,7 +131,7 @@
         'PORT': ''
     },
     'gencache': {
-        'ENGINE': 'django.db.backends.postgresql',
+        'ENGINE': 'django_postgrespool2',
         'NAME': os.environ.get("DB_CACHE_NAME"),
         'USER': os.environ.get("DB_CACHE_USERNAME"),
         'PASSWORD': os.environ.get("DB_CACHE_PASSWORD"),
@@ -140,6 +140,15 @@
     }
 }
 
+# Max connections is pool_size + max_overflow
+# Will idle at pool_size connections, overflow are for spikes in traffic
+
+DATABASE_POOL_ARGS = {
+    'max_overflow': 15,
+    'pool_size': 5,
+    'recycle': 300
+}
+
 DATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']
 
 RAVEN_CONFIG = {


Test patch: