internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: digitalfabrik/integreat-cms

Issue:
Repair tree is breaking
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->


### Steps to Reproduce

1. Run `integreat-cms-cli repair_tree` on a tree 
### Expected Behavior
Should never break


### Actual Behavior
<!-- A clear and concise description of what actually happened. -->


### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->

<details>
  <summary>Traceback</summary>

  ```
root@integreat-prod ~ # integreat-cms-cli repair_tree  31265
Detecting problems in tree with id 11730...
Page 31265:
	parent_id: None
	tree_id: 11730
	depth: 3 → 1
	lft: 1
	rgt: 4 → 2

💣 Orphans detected! The following pages share the tree id 11730 but don't have a relation to the root node:
Page 32488:
Traceback (most recent call last):
  File "/opt/integreat-cms/.venv/bin/integreat-cms-cli", line 52, in <module>
    main()
  File "/opt/integreat-cms/.venv/bin/integreat-cms-cli", line 48, in main
    execute_from_command_line(sys.argv)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/integreat_cms/core/management/commands/repair_tree.py", line 65, in handle
    self.check_for_orphans(root_node.tree_id)
  File "/opt/integreat-cms/.venv/lib/python3.9/site-packages/integreat_cms/core/management/commands/repair_tree.py", line 136, in check_for_orphans
    f"\tparent.tree_id: {orphan.parent.tree_id}"
AttributeError: 'NoneType' object has no attribute 'tree_id'
  ```

</details>



Discussion:

Resolving patch:
diff --git a/integreat_cms/core/management/commands/repair_tree.py b/integreat_cms/core/management/commands/repair_tree.py
--- a/integreat_cms/core/management/commands/repair_tree.py
+++ b/integreat_cms/core/management/commands/repair_tree.py
@@ -131,10 +131,9 @@ def check_for_orphans(self, tree_id):
             )
             for orphan in orphans:
                 self.stdout.write(self.bold(f"Page {orphan.id}:"))
-                self.print_error(
-                    f"\tparent_id: {orphan.parent_id}\n"
-                    f"\tparent.tree_id: {orphan.parent.tree_id}"
-                )
+                self.print_error(f"\tparent_id: {orphan.parent_id}")
+                if orphan.parent_id:
+                    self.print_error(f"\tparent.tree_id: {orphan.parent.tree_id}")
                 self.stdout.write(
                     self.bold(
                         f"\tdepth {orphan.depth}\n"


Test patch:
Repository: digitalfabrik/integreat-cms

Issue:
Increase speed of CSV export
### Describe the Bug
<!-- A clear and concise description of what the bug is. -->
#2593 introduced the option to export region feedback to CSV. However the testing on production and test server showed that in it's current state the export is very slow (~17s on production).

### Steps to Reproduce

1. Go to Testumgebung on the production server
2. Click on Feedback
3. Select an arbitrary amount of feedback entries
4. Open up network analysis in browser
5. Run the bulk action "export to CSV"
6. See that the action takes a few seconds

### Expected Behavior
<!-- A clear and concise description of what you expected to happen. -->
I'm not sure what a good threshold would be - maybe the standard 4s?

### Actual Behavior
<!-- A clear and concise description of what actually happened. -->
It takes considerably longer - around 17s in my test cases.

### Additional Information
<!-- Add any other context (e.g. logs, screenshots, etc.) about the problem here. -->

While testing this I noticed that the amount of selected feedback didn't really have an effect on the performance. Exporting 1 and 16 pages took the same loading time (the above mentioned 17s). I'm not sure if this is relevant, but I still wanted to mention it.

<details>
  <summary>Traceback</summary>

  ```
  ```

</details>



Discussion:

Resolving patch:
diff --git a/integreat_cms/cms/views/feedback/region_feedback_actions.py b/integreat_cms/cms/views/feedback/region_feedback_actions.py
--- a/integreat_cms/cms/views/feedback/region_feedback_actions.py
+++ b/integreat_cms/cms/views/feedback/region_feedback_actions.py
@@ -199,14 +199,10 @@ def export_region_feedback(
     )
 
     resource = FeedbackResource()
-    dataset = Dataset()
-
-    headers = resource.export().headers
-    dataset.headers = headers
-
-    for obj in selected_feedback:
-        data = resource.export_resource(obj)
-        dataset.append(data)
+    dataset = Dataset(
+        *(resource.export_resource(obj) for obj in selected_feedback),
+        headers=resource.export().headers,
+    )
 
     if file_format in (f.title for f in format_registry.formats()):
         blob = getattr(dataset, file_format)


Test patch:
Repository: openfun/marsha

Issue:
Integrate sentry
## Purpose

[Sentry](https://sentry.io) is a great tool to track and report application errors. Looks like a requirement for any Django project.

## Proposal

Add raven as a project requirement and configure sentry.

Reference documentation: https://docs.sentry.io/platforms/python/django/


Discussion:

Resolving patch:
diff --git a/marsha/settings.py b/marsha/settings.py
--- a/marsha/settings.py
+++ b/marsha/settings.py
@@ -11,6 +11,8 @@
 from django.utils.translation import gettext_lazy as _
 
 from configurations import Configuration, values
+import sentry_sdk
+from sentry_sdk.integrations.django import DjangoIntegration
 
 
 class Base(Configuration):
@@ -177,6 +179,25 @@ def SIMPLE_JWT(self):
             "AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
         }
 
+    @classmethod
+    def post_setup(cls):
+        """Post setup configuration.
+
+        This is the place where you can configure settings that require other
+        settings to be loaded.
+        """
+        super().post_setup()
+
+        # The DJANGO_SENTRY_DSN environment variable should be set to activate
+        # sentry for an environment
+        sentry_dsn = values.Value(None, environ_name="SENTRY_DSN")
+        if sentry_dsn is not None:
+            sentry_sdk.init(
+                dsn=sentry_dsn,
+                environment=cls.__name__.lower(),
+                integrations=[DjangoIntegration()],
+            )
+
 
 class Development(Base):
     """Development environment settings.


Test patch:
Repository: openfun/marsha

Issue:
Add Staging, PreProduction & Production settings
## Purpose

At the time of writing, available configurations for Marsha are: `Development` and `Test`. We need more settings for missing environments. 

## Proposal

- [ ] Add `Production` configuration
- [ ] Derive `Staging` and `Preproduction` configurations from `Production`


Discussion:

Resolving patch:
diff --git a/marsha/settings.py b/marsha/settings.py
--- a/marsha/settings.py
+++ b/marsha/settings.py
@@ -218,3 +218,27 @@ class Test(Base):
     AWS_SOURCE_BUCKET_NAME = "test-marsha-source"
 
     CLOUDFRONT_SIGNED_URLS_ACTIVE = False
+
+
+class Production(Base):
+    """Production environment settings.
+
+    You must define the DJANGO_ALLOWED_HOSTS environment variable in Production
+    configuration (and derived configurations):
+
+    DJANGO_ALLOWED_HOSTS="foo.com,foo.fr"
+    """
+
+    ALLOWED_HOSTS = values.ListValue(None)
+
+
+class Staging(Production):
+    """Staging environment settings."""
+
+    pass
+
+
+class PreProduction(Production):
+    """Pre-production environment settings."""
+
+    pass


Test patch:
Repository: openfun/marsha

Issue:
Consider moving the gitlint script to bin/
## Purpose

We use a dedicated script to lint git commits. It is currently located in `gitlint/gitlint_emoji.py`. I think we might consider moving it to the `bin/` directory as it's a project tool.

## Proposal

- [ ] `git mv gitlint/gitlint_emoji.py bin/`
- [ ] update `.gitlint` configuration to add `bin` to the `extra-path`


Discussion:

Resolving patch:
diff --git a/gitlint/gitlint_emoji.py b/lib/gitlint/gitlint_emoji.py
similarity index 100%
rename from gitlint/gitlint_emoji.py
rename to lib/gitlint/gitlint_emoji.py


Test patch:
Repository: openfun/marsha

Issue:
Implement CSP in marsha response
## Feature Request

To increase the security and prevent XSS [Content Security Policy](https://content-security-policy.com/) can be implemented to control which dynamic resources are allowed to load.

**Describe the solution you'd like**

We have to list all the dynamic resources uses in marsha and see if we want to distinguish resources (allow by resource type like media, style, script, ...) or the same rule for every resources.

A django middleware exists to help the implementation of CSP: https://github.com/mozilla/django-csp

**Do you want to work on it through a Pull Request?**

I can yes.



Discussion:

Resolving patch:
diff --git a/src/backend/marsha/settings.py b/src/backend/marsha/settings.py
--- a/src/backend/marsha/settings.py
+++ b/src/backend/marsha/settings.py
@@ -73,6 +73,14 @@ class Base(Configuration):
 
     SITE_ID = 1
 
+    SECURE_BROWSER_XSS_FILTER = True
+    SESSION_COOKIE_SECURE = True
+    SECURE_CONTENT_TYPE_NOSNIFF = True
+    CSRF_COOKIE_SECURE = True
+    SILENCED_SYSTEM_CHECKS = [
+        "security.W019"  # Disable because we want to use SAMEORIGIN as value for X_FRAME_OPTIONS
+    ]
+
     # Application definition
 
     INSTALLED_APPS = [
@@ -371,6 +379,12 @@ class Production(Base):
 
     ALLOWED_HOSTS = values.ListValue(None)
     AWS_SOURCE_BUCKET_NAME = values.Value("production-marsha-source")
+    # Force to redirect traffic to HTTPS protocol
+    SECURE_SSL_REDIRECT = True
+
+    # Configure HSTS
+    # https://docs.djangoproject.com/en/2.2/ref/middleware/#http-strict-transport-security
+    SECURE_HSTS_SECONDS = 3600
 
     # Helper to easily know if static files in AWS is activated
     STATICFILES_AWS_ENABLED = True


Test patch:
Repository: openfun/marsha

Issue:
Searching a playlist by text raises a 500 error
## Bug Report

**Expected behavior/code**
In the admin, it should be possible to search a playlist by text.

**Actual Behavior**
Searching a playlist by text raises a 500 error (https://sentry.io/organizations/gip-fun-mooc/issues/1856670127/?project=1298925&query=is%3Aunresolved)

**Steps to Reproduce**
1. go to Marsha admin playlist list page: localhost:8070/admin/core/playlist/
2. Type a search in the search field:

<img src="https://user-images.githubusercontent.com/1427165/91073123-db4d7680-e63a-11ea-97c9-4c6c604f1d63.png" width="350"/>

3. Enjoy the 500!

**Environment**
- Marsha version: 3.10.0
- Platform: Docker

**Possible Solution**
I think the error comes from this line https://github.com/openfun/marsha/blob/master/src/backend/marsha/core/admin.py#L380 which is trying to search for a text on a foreignkey...

The first solution that comes to mind is to replace it by : "portable_to__title", "portable_to__id" and "portable_to__lti_id"...

However, I'm not sure we want to search a playlist by the title or ids of the playlists to which it is portable...

So finally, I think we should remove this line.



Discussion:

Resolving patch:
diff --git a/src/backend/marsha/core/admin.py b/src/backend/marsha/core/admin.py
--- a/src/backend/marsha/core/admin.py
+++ b/src/backend/marsha/core/admin.py
@@ -377,7 +377,9 @@ class PlaylistAdmin(admin.ModelAdmin):
         "consumer_site__name",
         "organization__name",
         "lti_id",
-        "portable_to",
+        "portable_to__title",
+        "portable_to__lti_id",
+        "portable_to__id",
         "title",
     )
     verbose_name = _("Playlist")


Test patch:
Repository: openfun/marsha

Issue:
Properly clause websocket connection on video/webinar deletion
## Bug Report

**Problematic Behavior**

When a video/webinar is deleted, a websocket connection is still open. The dashboard is unmounted by react so it tries to close it but an error is thrown because on closing the connection, the weboscket tries to fetch the attached live session in database but this one does not exists anymore.

**Expected behavior/code**

When a video/webinar is deleted, the websocket should be properly closed.

**Steps to Reproduce**
1. Create a webinar
2. Delete it


**Additional context/Screenshots**

https://gip-fun-mooc.sentry.io/share/issue/668071c3736a446a890af2b99df1c6c6/



Discussion:

Resolving patch:
diff --git a/src/backend/marsha/websocket/consumers/video.py b/src/backend/marsha/websocket/consumers/video.py
--- a/src/backend/marsha/websocket/consumers/video.py
+++ b/src/backend/marsha/websocket/consumers/video.py
@@ -175,8 +175,12 @@ async def disconnect(self, code):
         # Leave room group
         await self.channel_layer.group_discard(self.room_group_name, self.channel_name)
         if not await self._is_admin():
-            live_session = await self.retrieve_live_session()
-            await self.reset_live_session(live_session)
+            try:
+                live_session = await self.retrieve_live_session()
+                await self.reset_live_session(live_session)
+            except ConnectionRefusedError:
+                # No live session found, nothing to do
+                pass
 
     async def video_updated(self, event):
         """Listener for the video_updated event."""


Test patch:
diff --git a/src/backend/marsha/websocket/tests/test_consumers_video.py b/src/backend/marsha/websocket/tests/test_consumers_video.py
--- a/src/backend/marsha/websocket/tests/test_consumers_video.py
+++ b/src/backend/marsha/websocket/tests/test_consumers_video.py
@@ -655,6 +655,28 @@ async def test_video_update_instructor_channel_layer(self):
 
         await communicator.disconnect()
 
+    async def test_video_delete_channel_layer(self):
+        """Disconnecting from a deleted video should not raise."""
+
+        playlist_access = await self._get_playlist_access(
+            playlist=self.some_video.playlist,
+            role=ADMINISTRATOR,
+        )
+
+        jwt_token = await self._get_user_access_token(user=playlist_access.user)
+
+        communicator = WebsocketCommunicator(
+            base_application,
+            f"ws/video/{self.some_video.id}/?jwt={jwt_token}",
+        )
+
+        connected, _subprotocol = await communicator.connect()
+        self.assertTrue(connected)
+
+        await sync_to_async(self.some_video.delete)()
+
+        await communicator.disconnect()
+
     async def test_thumbnail_update_channel_layer(self):
         """Message received on thumbnail_updated event."""
         thumbnail = await self._get_thumbnail()
Repository: openfun/marsha

Issue:
🐛(backend) licence not saved during creation video resource
## Bug Report

**Problematic Behavior**
When we create a video and set a licence, the licence is not saved.

[error-licence-2023-09-12 143121.webm](https://github.com/openfun/marsha/assets/25994652/60514ad8-07cd-4390-97c9-21eb3525ecc6)




Discussion:

Resolving patch:
diff --git a/src/backend/marsha/core/forms.py b/src/backend/marsha/core/forms.py
--- a/src/backend/marsha/core/forms.py
+++ b/src/backend/marsha/core/forms.py
@@ -35,6 +35,7 @@ class Meta:
             "playlist",
             "title",
             "upload_state",
+            "license",
         ]
 
     def clean_upload_state(self):


Test patch:
diff --git a/src/backend/marsha/core/tests/api/video/test_create.py b/src/backend/marsha/core/tests/api/video/test_create.py
--- a/src/backend/marsha/core/tests/api/video/test_create.py
+++ b/src/backend/marsha/core/tests/api/video/test_create.py
@@ -78,6 +78,7 @@ def test_api_video_create_by_playlist_admin(self):
                 "lti_id": "video_one",
                 "playlist": str(playlist.id),
                 "title": "Some video",
+                "license": "CC_BY-ND",
             },
             HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
         )
@@ -127,7 +128,7 @@ def test_api_video_create_by_playlist_admin(self):
                 "urls": None,
                 "xmpp": None,
                 "tags": [],
-                "license": None,
+                "license": "CC_BY-ND",
             },
         )
 
@@ -174,6 +175,7 @@ def test_api_video_create_by_playlist_instructor(self):
                 "lti_id": "video_one",
                 "playlist": str(playlist.id),
                 "title": "Some video",
+                "license": "CC_BY-ND",
             },
             HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
         )
@@ -223,7 +225,7 @@ def test_api_video_create_by_playlist_instructor(self):
                 "urls": None,
                 "xmpp": None,
                 "tags": [],
-                "license": None,
+                "license": "CC_BY-ND",
             },
         )
Repository: DataDog/dd-trace-py

Issue:
psycopg2 cursor's __enter__ method is not patched to be traced
See behavior here:

```python
>>> import ddtrace
>>> ddtrace.patch_all()
>>> import psycopg2
>>> conn = psycopg2.connect('postgresql://localhost')
>>> print(type(conn.cursor()))
<class 'ddtrace.contrib.dbapi.TracedCursor'>
>>> with conn.cursor() as cur:
...     print(type(cur))
<type 'psycopg2.extensions.cursor'>
```


Discussion:

Resolving patch:
diff --git a/ddtrace/contrib/dbapi/__init__.py b/ddtrace/contrib/dbapi/__init__.py
--- a/ddtrace/contrib/dbapi/__init__.py
+++ b/ddtrace/contrib/dbapi/__init__.py
@@ -75,6 +75,15 @@ def callproc(self, proc, args):
             finally:
                 s.set_metric("db.rowcount", self.rowcount)
 
+    def __enter__(self):
+        # previous versions of the dbapi didn't support context managers. let's
+        # reference the func that would be called to ensure that errors
+        # messages will be the same.
+        self.__wrapped__.__enter__
+
+        # and finally, yield the traced cursor.
+        return self
+
 
 class TracedConnection(wrapt.ObjectProxy):
     """ TracedConnection wraps a Connection with tracing code. """


Test patch:
diff --git a/tests/contrib/psycopg/test_psycopg.py b/tests/contrib/psycopg/test_psycopg.py
--- a/tests/contrib/psycopg/test_psycopg.py
+++ b/tests/contrib/psycopg/test_psycopg.py
@@ -82,6 +82,24 @@ def assert_conn_is_traced(self, tracer, db, service):
         eq_(span.meta["out.port"], TEST_PORT)
         eq_(span.span_type, "sql")
 
+    def test_cursor_ctx_manager(self):
+        # ensure cursors work with context managers
+        # https://github.com/DataDog/dd-trace-py/issues/228
+
+        conn, tracer = self._get_conn_and_tracer()
+        t = type(conn.cursor())
+        with conn.cursor() as cur:
+            assert t == type(cur), "%s != %s" % (t, type(cur))
+            cur.execute(query="select 'blah'")
+            rows = cur.fetchall()
+            assert len(rows) == 1, row
+            assert rows[0][0] == 'blah'
+
+        spans = tracer.writer.pop()
+        assert len(spans) == 1
+        span = spans[0]
+        eq_(span.name, "postgres.query")
+
     def test_disabled_execute(self):
         conn, tracer = self._get_conn_and_tracer()
         tracer.enabled = False
Repository: DataDog/dd-trace-py

Issue:
dd-trace-py messes with the root logger
```
has anyone else run into the issue of ddtrace-py turning on all default loggers for everything when running `patch_all()`? Weirdly, I can only replicate it within Docker, but it's definitely the `patch_all()` command that's causing it

[8:50 PM] 
same thing happens if i run a single `patch()` on any library, it seems

[8:52 PM] 
thinking it might be caused by this line: https://github.com/DataDog/dd-trace-py/blob/a50b5f5422716fae1c54b589cd448dc295b32757/ddtrace/monkey.py#L77

[8:53 PM] 
any reason that's `logging.info(...)` on the `logging` module instead of getting a logger and calling `.info()` on that?
```


Discussion:

Resolving patch:
diff --git a/ddtrace/contrib/mysql/__init__.py b/ddtrace/contrib/mysql/__init__.py
--- a/ddtrace/contrib/mysql/__init__.py
+++ b/ddtrace/contrib/mysql/__init__.py
@@ -28,13 +28,16 @@
 
 from ..util import require_modules
 
+
+log = logging.getLogger(__name__)
+
 # check `MySQL-python` availability
 required_modules = ['_mysql']
 
 with require_modules(required_modules) as missing_modules:
     if not missing_modules:
         # MySQL-python package is not supported at the moment
-        logging.debug('failed to patch mysql-python: integration not available')
+        log.debug('failed to patch mysql-python: integration not available')
 
 # check `mysql-connector` availability
 required_modules = ['mysql.connector']
diff --git a/ddtrace/monkey.py b/ddtrace/monkey.py
--- a/ddtrace/monkey.py
+++ b/ddtrace/monkey.py
@@ -11,6 +11,8 @@
 import threading
 
 
+log = logging.getLogger(__name__)
+
 # Default set of modules to automatically patch or not
 PATCH_MODULES = {
     'boto': False,
@@ -74,7 +76,7 @@ def patch(raise_errors=True, **patch_modules):
         if patched:
             count += 1
 
-    logging.info("patched %s/%s modules (%s)",
+    log.info("patched %s/%s modules (%s)",
         count,
         len(modules),
         ",".join(get_patched_modules()))
@@ -90,7 +92,7 @@ def patch_module(module, raise_errors=True):
     except Exception as exc:
         if raise_errors:
             raise
-        logging.debug("failed to patch %s: %s", module, exc)
+        log.debug("failed to patch %s: %s", module, exc)
         return False
 
 def get_patched_modules():
@@ -107,7 +109,7 @@ def _patch_module(module):
     path = 'ddtrace.contrib.%s' % module
     with _LOCK:
         if module in _PATCHED_MODULES:
-            logging.debug("already patched: %s", path)
+            log.debug("already patched: %s", path)
             return False
 
         try:


Test patch: