internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: open-telemetry/opentelemetry-python-contrib

Issue:
Add support for confluent-kafka v2.3

**Is your feature request related to a problem?**
We've recently upgraded our confluent-kafka python version to v2.3. But this version is not yet supported by the instrumentor.

**Describe the solution you'd like**
Confluent kafka version 2.3.x is supported by the instrumentor




Discussion:

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/package.py b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/package.py
--- a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/package.py
+++ b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/package.py
@@ -13,4 +13,4 @@
 # limitations under the License.
 
 
-_instruments = ("confluent-kafka >= 1.8.2, <= 2.2.0",)
+_instruments = ("confluent-kafka >= 1.8.2, <= 2.3.0",)
diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
--- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
+++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
@@ -65,7 +65,7 @@
         "instrumentation": "opentelemetry-instrumentation-celery==0.44b0.dev",
     },
     {
-        "library": "confluent-kafka >= 1.8.2, <= 2.2.0",
+        "library": "confluent-kafka >= 1.8.2, <= 2.3.0",
         "instrumentation": "opentelemetry-instrumentation-confluent-kafka==0.44b0.dev",
     },
     {


Test patch:
Repository: open-telemetry/opentelemetry-python-contrib

Issue:
Remove werkzeug from Flask instrumentation dependencies



Discussion:

Resolving patch:
diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
--- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
+++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py
@@ -84,10 +84,6 @@
         "library": "fastapi ~= 0.58",
         "instrumentation": "opentelemetry-instrumentation-fastapi==0.44b0.dev",
     },
-    {
-        "library": "werkzeug < 3.0.0",
-        "instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev",
-    },
     {
         "library": "flask >= 1.0",
         "instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev",


Test patch:
Repository: open-telemetry/opentelemetry-python-contrib

Issue:
Flask instrumentation DeprecationWarning - The '__version__' attribute is deprecated and will be removed in Flask 3.1
**Describe your environment**
With the just-release opentelemetry-instrumentation-flask 0.44b0 I get this from the flask instrumentation:

```
DeprecationWarning: The '__version__' attribute is deprecated and will be removed in Flask 3.1. Use feature detection or 'importlib.metadata.version("flask")' instead.
```

Problematic code is at https://github.com/open-telemetry/opentelemetry-python-contrib/blame/8daa8ad48108775d8e799a3abc3ed06f84b4c00e/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py#L254-L263 and caused by #2013.

Flask version is 3.0.2.

**Steps to reproduce**
Instrument Flask > 3

**What is the expected behavior?**
No DeprecationWarning

**What is the actual behavior?**
DeprecationWarning

**Additional context**
N/A


Discussion:

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py
--- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py
+++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py
@@ -245,22 +245,13 @@ def response_hook(span: Span, status: str, response_headers: List):
 from typing import Collection
 
 import flask
+import importlib_metadata as metadata
 from packaging import version as package_version
 
 import opentelemetry.instrumentation.wsgi as otel_wsgi
 from opentelemetry import context, trace
 from opentelemetry.instrumentation.flask.package import _instruments
 from opentelemetry.instrumentation.flask.version import __version__
-
-try:
-    flask_version = flask.__version__
-except AttributeError:
-    try:
-        from importlib import metadata
-    except ImportError:
-        import importlib_metadata as metadata
-    flask_version = metadata.version("flask")
-
 from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
 from opentelemetry.instrumentation.propagators import (
     get_global_response_propagator,
@@ -281,6 +272,8 @@ def response_hook(span: Span, status: str, response_headers: List):
 
 _excluded_urls_from_env = get_excluded_urls("FLASK")
 
+flask_version = metadata.version("flask")
+
 if package_version.parse(flask_version) >= package_version.parse("2.2.0"):
 
     def _request_ctx_ref() -> weakref.ReferenceType:


Test patch:
Repository: open-telemetry/opentelemetry-python-contrib

Issue:
opentelemetry-instrumentation-system-metrics depends on the SDK
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2493258af11df7f211567103635588f2813de7a3/instrumentation/opentelemetry-instrumentation-system-metrics/pyproject.toml#L29

**What is the expected behavior?**
Instrumentations should never depend directly on the SDK

**What is the actual behavior?**
There is a hard dep

**Additional context**
The only usage of the SDK in real code is or this util function https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2493258af11df7f211567103635588f2813de7a3/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py#L94

This should be inlined or removed and the SDK dep removed




Discussion:
Can work on this one
Thanks @emdneto assigned to you and appreciate your help

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py
--- a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py
+++ b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py
@@ -91,7 +91,6 @@
 from opentelemetry.instrumentation.system_metrics.package import _instruments
 from opentelemetry.instrumentation.system_metrics.version import __version__
 from opentelemetry.metrics import CallbackOptions, Observation, get_meter
-from opentelemetry.sdk.util import get_dict_as_key
 
 _logger = logging.getLogger(__name__)
 
@@ -638,8 +637,8 @@ def _get_system_network_connections(
                     net_connection, metric
                 )
 
-            connection_counters_key = get_dict_as_key(
-                self._system_network_connections_labels
+            connection_counters_key = tuple(
+                sorted(self._system_network_connections_labels.items())
             )
 
             if connection_counters_key in connection_counters:


Test patch:
Repository: JoaquinAmatRodrigo/skforecast

Issue:
Miscalculated residuals in plot_residuals()
The source code in `plot_residuals()` calculate the residuals as follows:

https://github.com/JoaquinAmatRodrigo/skforecast/blob/310915dc5b07b82acd731f43ab0f6b776ba5c6fd/skforecast/plot/plot.py#L59

But according to [Rob Hyndman's book (FPP3)](https://otexts.com/fpp3/accuracy.html#forecast-errors), the correct calculation should be:

$$e_{T+h} = y_{T+h} - \hat{y}_{T+h\|T}$$

Where $y_{T+h}$ are the "*Ground truth (correct) values*" and $\hat{y}_{T+h\|T}$ are the "*Values of predictions*"


So, the above code should change to:

```
residuals = y_true - y_pred
```


Discussion:

Resolving patch:
diff --git a/skforecast/datasets/datasets.py b/skforecast/datasets/datasets.py
--- a/skforecast/datasets/datasets.py
+++ b/skforecast/datasets/datasets.py
@@ -130,7 +130,7 @@ def fetch_dataset(
             'date_format': '%Y-%m-%d %H:%M:%S',
             'freq': 'H',
             'description': (
-                'Hourly measures of several air quimical pollutant (pm2.5, co, no, '
+                'Hourly measures of several air chemical pollutant (pm2.5, co, no, '
                 'no2, pm10, nox, o3, so2) at Valencia city.'
             ),
             'source': (
@@ -375,4 +375,4 @@ def load_demo_dataset(version: str = 'latest') -> pd.Series:
     df = df['y']
     df = df.sort_index()
 
-    return df
\ No newline at end of file
+    return df
diff --git a/skforecast/plot/plot.py b/skforecast/plot/plot.py
--- a/skforecast/plot/plot.py
+++ b/skforecast/plot/plot.py
@@ -56,7 +56,7 @@ def plot_residuals(
         )
         
     if residuals is None:
-        residuals = y_pred - y_true
+        residuals = y_true - y_pred
             
     if fig is None:
         fig = plt.figure(constrained_layout=True, **fig_kw)


Test patch:
Repository: ccnmtl/django-pagetree

Issue:
Multiple elements with the same ID are rendering on the "Add Pageblock" form
In the "Add Pageblock" form, the modal forms render inputs with the `id` set to `id_label` and `id_css_extra`. Because there's multiple pageblock adding modals in the dom, that causes multiple elements with the same `id` to be rendered, which goes against the assumptions for an html ID. This causes input selection to behave strangely: I'm unable to select the inputs with a left-click in Firefox, I need to work around it by right-clicking.

The solution is just making these id's unique so they don't conflict with each other



Discussion:

Resolving patch:
diff --git a/pagetree/models.py b/pagetree/models.py
--- a/pagetree/models.py
+++ b/pagetree/models.py
@@ -1,3 +1,4 @@
+import random
 from django.contrib.auth.models import User
 from django.core.cache import cache
 from django.db import models
@@ -382,10 +383,22 @@ def available_pageblocks(self):
         return self.hierarchy.available_pageblocks()
 
     def add_pageblock_form(self):
-        class EditForm(forms.Form):
-            label = forms.CharField()
-            css_extra = forms.CharField(label="extra CSS classes")
-        return EditForm()
+        # This unique id should instead be derived from the block type's
+        # ID, but that requires a new templatetag. This works for now.
+        unique_id = random.randint(0, 10000)
+
+        class AddPageBlockForm(forms.Form):
+            label = forms.CharField(
+                widget=forms.TextInput(
+                    attrs={'id': 'id_label_%d' % unique_id}
+                ))
+            css_extra = forms.CharField(
+                label='extra CSS classes',
+                widget=forms.TextInput(
+                    attrs={'id': 'id_css_extra_%d' % unique_id}
+                ))
+
+        return AddPageBlockForm()
 
     def get_first_leaf(self):
         if self.is_leaf():


Test patch:
Repository: ccnmtl/django-pagetree

Issue:
Custom pageblocks in Hierarchy menu
Jess has a feature request for pagetree:

WORTH has a giant hierarchy menu: https://worth2.ccnmtl.columbia.edu/pages/edit/ and it would be nice to see which sections have which pageblocks on them. She says it shouldn't list text blocks, html blocks, quizzes etc., since many of those will be present on every page.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,7 @@
 
 setup(
     name="django-pagetree",
-    version="1.1.4",
+    version="1.1.5",
     author="Anders Pearson",
     author_email="anders@columbia.edu",
     url="https://github.com/ccnmtl/django-pagetree",


Test patch:
Repository: ccnmtl/django-pagetree

Issue:
admin templates requires django-smartif but doesn't list it in setup.py
should make it an explicit requirement so it's found at install time rather than as a 500 error, or just remove it.



Discussion:
Pagetree doesn't seem to have admin templates anymore, so I think this is no longer an issue...


Resolving patch:
diff --git a/pagetree/models.py b/pagetree/models.py
--- a/pagetree/models.py
+++ b/pagetree/models.py
@@ -360,11 +360,13 @@ class EditSectionForm(forms.Form):
             slug = forms.CharField(initial=self.slug)
             show_toc = forms.BooleanField(
                 initial=self.show_toc,
+                required=False,
                 label="Show Table of Contents",
                 help_text=("list table of contents of "
                            "immediate child sections (if applicable)"))
             deep_toc = forms.BooleanField(
                 initial=self.deep_toc,
+                required=False,
                 label="Show Deep Table of Contents",
                 help_text=(
                     "include children of children (etc) in TOC. "
diff --git a/pagetree/views.py b/pagetree/views.py
--- a/pagetree/views.py
+++ b/pagetree/views.py
@@ -102,8 +102,13 @@ def edit_section(request, section_id, success_url=None):
     section.save_version(request.user, activity="edit section")
     section.label = request.POST.get('label', '')
     section.slug = slugify(request.POST.get('slug', section.label))[:50]
-    section.show_toc = request.POST.get('show_toc', False)
-    section.deep_toc = request.POST.get('deep_toc', False)
+
+    value = request.POST.get('show_toc', False)
+    section.show_toc = value in ('True', True, 'on')
+
+    value = request.POST.get('deep_toc', False)
+    section.deep_toc = value in ('True', True, 'on')
+
     section.save()
     section.enforce_slug()
     section.save()


Test patch:
Repository: getredash/redash

Issue:
Redesign queryfiddle page
Attached are 2 modes of the queryfiddle page: dataset and query.
Thanks @yosefw

![dataset - table](https://f.cloud.github.com/assets/1098126/2319734/e1700534-a382-11e3-95e2-8947d0d391f0.png)
![dataset - edit query](https://f.cloud.github.com/assets/1098126/2319735/e38cbdbc-a382-11e3-848b-053d0a7097f2.png)

Redesign queryfiddle page
Attached are 2 modes of the queryfiddle page: dataset and query.
Thanks @yosefw

![dataset - table](https://f.cloud.github.com/assets/1098126/2319734/e1700534-a382-11e3-95e2-8947d0d391f0.png)
![dataset - edit query](https://f.cloud.github.com/assets/1098126/2319735/e38cbdbc-a382-11e3-848b-053d0a7097f2.png)

Redesign queryfiddle page
Attached are 2 modes of the queryfiddle page: dataset and query.
Thanks @yosefw

![dataset - table](https://f.cloud.github.com/assets/1098126/2319734/e1700534-a382-11e3-95e2-8947d0d391f0.png)
![dataset - edit query](https://f.cloud.github.com/assets/1098126/2319735/e38cbdbc-a382-11e3-848b-053d0a7097f2.png)



Discussion:

Resolving patch:
diff --git a/redash/controllers.py b/redash/controllers.py
--- a/redash/controllers.py
+++ b/redash/controllers.py
@@ -32,10 +32,11 @@ def ping():
 @app.route('/admin/<anything>')
 @app.route('/dashboard/<anything>')
 @app.route('/queries')
-@app.route('/queries/<anything>')
+@app.route('/queries/<query_id>')
+@app.route('/queries/<query_id>/<anything>')
 @app.route('/')
 @auth.required
-def index(anything=None):
+def index(**kwargs):
     email_md5 = hashlib.md5(current_user.email.lower()).hexdigest()
     gravatar_url = "https://www.gravatar.com/avatar/%s?s=40" % email_md5
 
@@ -243,7 +244,7 @@ def post(self, query_id):
             query_def['latest_query_data'] = query_def.pop('latest_query_data_id')
 
         models.Query.update_instance(query_id, **query_def)
-        
+
         query = models.Query.get_by_id(query_id)
 
         return query.to_dict(with_result=False, with_visualizations=True)


Test patch:
Repository: getredash/redash

Issue:
When two columns have the same name their values get overriden
```
SELECT 1, 2 
```

Will result in two columns having both the same value.



Discussion:

Resolving patch:
diff --git a/redash/data/query_runner_pg.py b/redash/data/query_runner_pg.py
--- a/redash/data/query_runner_pg.py
+++ b/redash/data/query_runner_pg.py
@@ -43,12 +43,26 @@ def query_runner(query):
             cursor.execute(query)
             wait(connection)
 
-            column_names = [col.name for col in cursor.description]
+            column_names = set()
+            columns = []
+            duplicates_counter = 1
+
+            for column in cursor.description:
+                # TODO: this deduplication needs to be generalized and reused in all query runners.
+                column_name = column.name
+                if column_name in column_names:
+                    column_name = column_name + str(duplicates_counter)
+                    duplicates_counter += 1
+
+                column_names.add(column_name)
+
+                columns.append({
+                    'name': column_name,
+                    'friendly_name': column_friendly_name(column_name),
+                    'type': None
+                })
 
             rows = [dict(zip(column_names, row)) for row in cursor]
-            columns = [{'name': col.name,
-                        'friendly_name': column_friendly_name(col.name),
-                        'type': None} for col in cursor.description]
 
             data = {'columns': columns, 'rows': rows}
             json_data = json.dumps(data, cls=JSONEncoder)


Test patch:
Repository: getredash/redash

Issue:
User can't add another dashboard after creating one without refreshing



Discussion:

Resolving patch:
diff --git a/redash/tasks.py b/redash/tasks.py
--- a/redash/tasks.py
+++ b/redash/tasks.py
@@ -58,8 +58,8 @@ def add_task(cls, query, data_source, scheduled=False):
 
             pipe = redis_connection.pipeline()
             try:
-                pipe.watch('query_hash_job:%s' % query_hash)
-                job_id = pipe.get('query_hash_job:%s' % query_hash)
+                pipe.watch(cls._job_lock_id(query_hash, data_source.id))
+                job_id = pipe.get(cls._job_lock_id(query_hash, data_source.id))
                 if job_id:
                     logging.info("[Manager][%s] Found existing job: %s", query_hash, job_id)
 
@@ -75,7 +75,7 @@ def add_task(cls, query, data_source, scheduled=False):
                     result = execute_query.apply_async(args=(query, data_source.id), queue=queue_name)
                     job = cls(async_result=result)
                     logging.info("[Manager][%s] Created new job: %s", query_hash, job.id)
-                    pipe.set('query_hash_job:%s' % query_hash, job.id)
+                    pipe.set(cls._job_lock_id(query_hash, data_source.id), job.id)
                     pipe.execute()
                 break
 
@@ -116,6 +116,9 @@ def to_dict(self):
     def cancel(self):
         return self._async_result.revoke(terminate=True)
 
+    @staticmethod
+    def _job_lock_id(query_hash, data_source_id):
+        return "query_hash_job:%s:%s" % (data_source_id, query_hash)
 
 @celery.task(base=BaseTask)
 def refresh_queries():
@@ -178,11 +181,11 @@ def execute_query(self, query, data_source_id):
 
     self.update_state(state='STARTED', meta={'start_time': start_time, 'error': error, 'custom_message': ''})
 
-    # TODO: it is possible that storing the data will fail, and we will need to retry
-    # while we already marked the job as done
     # Delete query_hash
-    redis_connection.delete('query_hash_job:%s' % query_hash)
+    redis_connection.delete(QueryTask._job_lock_id(query_hash, data_source.id))
 
+    # TODO: it is possible that storing the data will fail, and we will need to retry
+    # while we already marked the job as done
     if not error:
         query_result = models.QueryResult.store_result(data_source.id, query_hash, query, data, run_time, datetime.datetime.utcnow())
     else:


Test patch:
Repository: getredash/redash

Issue:
HTTP caching headers for /api/query_results
(take into account TTL and other factors)

Related: #145.



Discussion:
Related: #243.

QueryResult calls by id can be cached forever. Can be huge win for performance, now that we load it separately. 


Resolving patch:
diff --git a/redash/cache.py b/redash/cache.py
new file mode 100644
--- /dev/null
+++ b/redash/cache.py
@@ -0,0 +1,8 @@
+from flask import make_response
+from functools import update_wrapper
+
+ONE_YEAR = 60 * 60 * 24 * 365.25
+
+headers = {
+  'Cache-Control': 'max-age=%d' % ONE_YEAR
+}
diff --git a/redash/controllers.py b/redash/controllers.py
--- a/redash/controllers.py
+++ b/redash/controllers.py
@@ -26,6 +26,7 @@
 import logging
 from tasks import QueryTask
 
+from cache import headers as cache_headers
 
 @app.route('/ping', methods=['GET'])
 def ping():
@@ -417,7 +418,8 @@ class QueryResultAPI(BaseResource):
     def get(self, query_result_id):
         query_result = models.QueryResult.get_by_id(query_result_id)
         if query_result:
-            return {'query_result': query_result.to_dict()}
+            data = json.dumps({'query_result': query_result.to_dict()}, cls=utils.JSONEncoder)
+            return make_response(data, 200, cache_headers)
         else:
             abort(404)
 


Test patch:
Repository: getredash/redash

Issue:
Cancelling queries sends them into "limbo"
If you cancel a query, it doesn't delete the lock which prevents it from running again.
1. If Celery raises an exception when cancelling a task, we need to handle it and cancel the task at this point.
2. Expire the lock keys after predefined time.
3. When locking, if it's possible to check if a job still running, verify it still running/exists, if not - ignore the lock.



Discussion:

Resolving patch:
diff --git a/redash/controllers.py b/redash/controllers.py
--- a/redash/controllers.py
+++ b/redash/controllers.py
@@ -111,7 +111,6 @@ def status_api():
 
     manager_status = redis_connection.hgetall('redash:status')
     status['manager'] = manager_status
-    status['manager']['queue_size'] = redis_connection.llen('queries') + redis_connection.llen('scheduled_queries')
     status['manager']['outdated_queries_count'] = models.Query.outdated_queries().count()
 
     queues = {}
diff --git a/redash/tasks.py b/redash/tasks.py
--- a/redash/tasks.py
+++ b/redash/tasks.py
@@ -1,6 +1,7 @@
 import time
 import datetime
 import logging
+import itertools
 import redis
 from celery import Task
 from celery.result import AsyncResult
@@ -64,7 +65,12 @@ def add_task(cls, query, data_source, scheduled=False):
                     logging.info("[Manager][%s] Found existing job: %s", query_hash, job_id)
 
                     job = cls(job_id=job_id)
-                else:
+                    if job.is_cancelled:
+                        logging.info("[%s] job found cancelled already, removing lock", query_hash)
+                        redis_connection.delete(QueryTask._job_lock_id(query_hash, data_source.id))
+                        job = None
+
+                if not job:
                     pipe.multi()
 
                     if scheduled:
@@ -113,6 +119,14 @@ def to_dict(self):
             'query_result_id': query_result_id,
         }
 
+    @property
+    def is_cancelled(self):
+        return self._async_result.status == 'REVOKED'
+
+    @property
+    def celery_status(self):
+        return self._async_result.status
+
     def cancel(self):
         return self._async_result.revoke(terminate=True)
 


Test patch: