{"instance_id": "django__django-11133", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/http/response.py b/django/http/response.py\nindex 6a84e193ba..ea423bca90 100644\n--- a/django/http/response.py\n+++ b/django/http/response.py\n@@ -229,7 +229,7 @@ class HttpResponseBase:\n         # Handle string types -- we can't rely on force_bytes here because:\n         # - Python attempts str conversion first\n         # - when self._charset != 'utf-8' it re-encodes the content\n-        if isinstance(value, bytes):\n+        if isinstance(value, (bytes, memoryview)):\n             return bytes(value)\n         if isinstance(value, str):\n             return bytes(value.encode(self.charset))\n@@ -309,7 +309,7 @@ class HttpResponse(HttpResponseBase):\n     @content.setter\n     def content(self, value):\n         # Consume iterators upon assignment to allow repeated iteration.\n-        if hasattr(value, '__iter__') and not isinstance(value, (bytes, str)):\n+        if hasattr(value, '__iter__') and not isinstance(value, (bytes, memoryview, str)):\n             content = b''.join(self.make_bytes(chunk) for chunk in value)\n             if hasattr(value, 'close'):\n                 try:\n", "model": "claude-sonnet-5-5", "steps": 10, "finished": true, "patch_lines": 22, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 22, "steps": 10}], "ms": 26235}
{"instance_id": "django__django-11138", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py\nindex 50f85e0621..b90a0eb555 100644\n--- a/django/db/backends/mysql/operations.py\n+++ b/django/db/backends/mysql/operations.py\n@@ -69,8 +69,10 @@ class DatabaseOperations(BaseDatabaseOperations):\n             return \"DATE(%s)\" % (field_name)\n \n     def _convert_field_to_tz(self, field_name, tzname):\n-        if settings.USE_TZ:\n-            field_name = \"CONVERT_TZ(%s, 'UTC', '%s')\" % (field_name, tzname)\n+        if tzname and settings.USE_TZ and self.connection.timezone_name != tzname:\n+            field_name = \"CONVERT_TZ(%s, '%s', '%s')\" % (\n+                field_name, self.connection.timezone_name, tzname,\n+            )\n         return field_name\n \n     def datetime_cast_date_sql(self, field_name, tzname):\ndiff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py\nindex c1afb2ed5e..049654917b 100644\n--- a/django/db/backends/oracle/operations.py\n+++ b/django/db/backends/oracle/operations.py\n@@ -95,13 +95,20 @@ END;\n     _tzname_re = re.compile(r'^[\\w/:+-]+$')\n \n     def _convert_field_to_tz(self, field_name, tzname):\n-        if not settings.USE_TZ:\n+        if not (settings.USE_TZ and tzname):\n             return field_name\n         if not self._tzname_re.match(tzname):\n             raise ValueError(\"Invalid time zone name: %s\" % tzname)\n-        # Convert from UTC to local time, returning TIMESTAMP WITH TIME ZONE\n-        # and cast it back to TIMESTAMP to strip the TIME ZONE details.\n-        return \"CAST((FROM_TZ(%s, '0:00') AT TIME ZONE '%s') AS TIMESTAMP)\" % (field_name, tzname)\n+        # Convert from connection timezone to the local time, returning\n+        # TIMESTAMP WITH TIME ZONE and cast it back to TIMESTAMP to strip the\n+        # TIME ZONE details.\n+        if self.connection.timezone_name != tzname:\n+            return \"CAST((FROM_TZ(%s, '%s') AT TIME ZONE '%s') AS TIMESTAMP)\" % (\n+                field_name,\n+                self.connection.timezone_name,\n+                tzname,\n+            )\n+        return field_name\n \n     def datetime_cast_date_sql(self, field_name, tzname):\n         field_name = self._convert_field_to_tz(field_name, tzname)\ndiff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py\nindex 6a19236c48..7d8658ce3b 100644\n--- a/django/db/backends/sqlite3/base.py\n+++ b/django/db/backends/sqlite3/base.py\n@@ -195,10 +195,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):\n         conn = Database.connect(**conn_params)\n         conn.create_function(\"django_date_extract\", 2, _sqlite_datetime_extract)\n         conn.create_function(\"django_date_trunc\", 2, _sqlite_date_trunc)\n-        conn.create_function(\"django_datetime_cast_date\", 2, _sqlite_datetime_cast_date)\n-        conn.create_function(\"django_datetime_cast_time\", 2, _sqlite_datetime_cast_time)\n-        conn.create_function(\"django_datetime_extract\", 3, _sqlite_datetime_extract)\n-        conn.create_function(\"django_datetime_trunc\", 3, _sqlite_datetime_trunc)\n+        conn.create_function(\"django_datetime_cast_date\", 3, _sqlite_datetime_cast_date)\n+        conn.create_function(\"django_datetime_cast_time\", 3, _sqlite_datetime_cast_time)\n+        conn.create_function(\"django_datetime_extract\", 4, _sqlite_datetime_extract)\n+        conn.create_function(\"django_datetime_trunc\", 4, _sqlite_datetime_trunc)\n         conn.create_function(\"django_time_extract\", 2, _sqlite_time_extract)\n         conn.create_function(\"django_time_trunc\", 2, _sqlite_time_trunc)\n         conn.create_function(\"django_time_diff\", 2, _sqlite_time_diff)\n@@ -398,14 +398,16 @@ class SQLiteCursorWrapper(Database.Cursor):\n         return FORMAT_QMARK_REGEX.sub('?', query).replace('%%', '%')\n \n \n-def _sqlite_datetime_parse(dt, tzname=None):\n+def _sqlite_datetime_parse(dt, tzname=None, conn_tzname=None):\n     if dt is None:\n         return None\n     try:\n         dt = backend_utils.typecast_timestamp(dt)\n     except (TypeError, ValueError):\n         return None\n-    if tzname is not None:\n+    if conn_tzname:\n+        dt = dt.replace(tzinfo=pytz.timezone(conn_tzname))\n+    if tzname is not None and tzname != conn_tzname:\n         dt = timezone.localtime(dt, pytz.timezone(tzname))\n     return dt\n \n@@ -443,22 +445,22 @@ def _sqlite_time_trunc(lookup_type, dt):\n         return \"%02i:%02i:%02i\" % (dt.hour, dt.minute, dt.second)\n \n \n-def _sqlite_datetime_cast_date(dt, tzname):\n-    dt = _sqlite_datetime_parse(dt, tzname)\n+def _sqlite_datetime_cast_date(dt, tzname, conn_tzname):\n+    dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)\n     if dt is None:\n         return None\n     return dt.date().isoformat()\n \n \n-def _sqlite_datetime_cast_time(dt, tzname):\n-    dt = _sqlite_datetime_parse(dt, tzname)\n+def _sqlite_datetime_cast_time(dt, tzname, conn_tzname):\n+    dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)\n     if dt is None:\n         return None\n     return dt.time().isoformat()\n \n \n-def _sqlite_datetime_extract(lookup_type, dt, tzname=None):\n-    dt = _sqlite_datetime_parse(dt, tzname)\n+def _sqlite_datetime_extract(lookup_type, dt, tzname=None, conn_tzname=None):\n+    dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)\n     if dt is None:\n         return None\n     if lookup_type == 'week_day':\n@@ -473,8 +475,8 @@ def _sqlite_datetime_extract(lookup_type, dt, tzname=None):\n         return getattr(dt, lookup_type)\n \n \n-def _sqlite_datetime_trunc(lookup_type, dt, tzname):\n-    dt = _sqlite_datetime_parse(dt, tzname)\n+def _sqlite_datetime_trunc(lookup_type, dt, tzname, conn_tzname):\n+    dt = _sqlite_datetime_parse(dt, tzname, conn_tzname)\n     if dt is None:\n         return None\n     if lookup_type == 'year':\ndiff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py\nindex c4b02e5c60..50e4cc60a5 100644\n--- a/django/db/backends/sqlite3/operations.py\n+++ b/django/db/backends/sqlite3/operations.py\n@@ -84,27 +84,29 @@ class DatabaseOperations(BaseDatabaseOperations):\n     def time_trunc_sql(self, lookup_type, field_name):\n         return \"django_time_trunc('%s', %s)\" % (lookup_type.lower(), field_name)\n \n-    def _convert_tzname_to_sql(self, tzname):\n-        return \"'%s'\" % tzname if settings.USE_TZ else 'NULL'\n+    def _convert_tznames_to_sql(self, tzname):\n+        if settings.USE_TZ:\n+            return \"'%s'\" % tzname, \"'%s'\" % self.connection.timezone_name\n+        return 'NULL', 'NULL'\n \n     def datetime_cast_date_sql(self, field_name, tzname):\n-        return \"django_datetime_cast_date(%s, %s)\" % (\n-            field_name, self._convert_tzname_to_sql(tzname),\n+        return \"django_datetime_cast_date(%s, %s, %s)\" % (\n+            field_name, *self._convert_tznames_to_sql(tzname),\n         )\n \n     def datetime_cast_time_sql(self, field_name, tzname):\n-        return \"django_datetime_cast_time(%s, %s)\" % (\n-            field_name, self._convert_tzname_to_sql(tzname),\n+        return \"django_datetime_cast_time(%s, %s, %s)\" % (\n+            field_name, *self._convert_tznames_to_sql(tzname),\n         )\n \n     def datetime_extract_sql(self, lookup_type, field_name, tzname):\n-        return \"django_datetime_extract('%s', %s, %s)\" % (\n-            lookup_type.lower(), field_name, self._convert_tzname_to_sql(tzname),\n+        return \"django_datetime_extract('%s', %s, %s, %s)\" % (\n+            lookup_type.lower(), field_name, *self._convert_tznames_to_sql(tzname),\n         )\n \n     def datetime_trunc_sql(self, lookup_type, field_name, tzname):\n-        return \"django_datetime_trunc('%s', %s, %s)\" % (\n-            lookup_type.lower(), field_name, self._convert_tzname_to_sql(tzname),\n+        return \"django_datetime_trunc('%s', %s, %s, %s)\" % (\n+            lookup_type.lower(), field_name, *self._convert_tznames_to_sql(tzname),\n         )\n \n     def time_extract_sql(self, lookup_type, field_name):\n", "model": "claude-sonnet-5-5", "steps": 14, "finished": true, "patch_lines": 168, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 4, "diff_lines": 168, "steps": 14}], "ms": 55917}
{"instance_id": "django__django-11141", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py\nindex 8c308621d2..d075fcc5df 100644\n--- a/django/db/migrations/loader.py\n+++ b/django/db/migrations/loader.py\n@@ -84,11 +84,6 @@ class MigrationLoader:\n                     continue\n                 raise\n             else:\n-                # Empty directories are namespaces.\n-                # getattr() needed on PY36 and older (replace w/attribute access).\n-                if getattr(module, '__file__', None) is None:\n-                    self.unmigrated_apps.add(app_config.label)\n-                    continue\n                 # Module is not a package (e.g. migrations.py).\n                 if not hasattr(module, '__path__'):\n                     self.unmigrated_apps.add(app_config.label)\n", "model": "claude-sonnet-5-5", "steps": 4, "finished": true, "patch_lines": 16, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 16, "steps": 4}], "ms": 15147}
{"instance_id": "django__django-11149", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py\nindex 880a2cc17b..471ef0b476 100644\n--- a/django/contrib/admin/options.py\n+++ b/django/contrib/admin/options.py\n@@ -2111,46 +2111,43 @@ class InlineModelAdmin(BaseModelAdmin):\n             queryset = queryset.none()\n         return queryset\n \n+    def _has_any_perms_for_target_model(self, request, perms):\n+        \"\"\"\n+        Called only for a ManyToManyField's auto-created through model.\n+        Return True if the user has any of the given permissions for the\n+        target model of the relationship.\n+        \"\"\"\n+        opts = self.opts\n+        for field in opts.fields:\n+            if field.remote_field and field.remote_field.model != self.parent_model:\n+                opts = field.remote_field.model._meta\n+                break\n+        return any(\n+            request.user.has_perm('%s.%s' % (opts.app_label, get_permission_codename(perm, opts)))\n+            for perm in perms\n+        )\n+\n     def has_add_permission(self, request, obj):\n         if self.opts.auto_created:\n-            # We're checking the rights to an auto-created intermediate model,\n-            # which doesn't have its own individual permissions. The user needs\n-            # to have the view permission for the related model in order to\n-            # be able to do anything with the intermediate model.\n-            return self.has_view_permission(request, obj)\n+            # Auto-created intermediate models don't have their own\n+            # permissions. The user needs the change permission for the\n+            # related model to modify the intermediate model.\n+            return self._has_any_perms_for_target_model(request, ['change'])\n         return super().has_add_permission(request)\n \n     def has_change_permission(self, request, obj=None):\n         if self.opts.auto_created:\n-            # We're checking the rights to an auto-created intermediate model,\n-            # which doesn't have its own individual permissions. The user needs\n-            # to have the view permission for the related model in order to\n-            # be able to do anything with the intermediate model.\n-            return self.has_view_permission(request, obj)\n+            return self._has_any_perms_for_target_model(request, ['change'])\n         return super().has_change_permission(request)\n \n     def has_delete_permission(self, request, obj=None):\n         if self.opts.auto_created:\n-            # We're checking the rights to an auto-created intermediate model,\n-            # which doesn't have its own individual permissions. The user needs\n-            # to have the view permission for the related model in order to\n-            # be able to do anything with the intermediate model.\n-            return self.has_view_permission(request, obj)\n+            return self._has_any_perms_for_target_model(request, ['change'])\n         return super().has_delete_permission(request, obj)\n \n     def has_view_permission(self, request, obj=None):\n         if self.opts.auto_created:\n-            opts = self.opts\n-            # The model was auto-created as intermediary for a many-to-many\n-            # Many-relationship; find the target model.\n-            for field in opts.fields:\n-                if field.remote_field and field.remote_field.model != self.parent_model:\n-                    opts = field.remote_field.model._meta\n-                    break\n-            return (\n-                request.user.has_perm('%s.%s' % (opts.app_label, get_permission_codename('view', opts))) or\n-                request.user.has_perm('%s.%s' % (opts.app_label, get_permission_codename('change', opts)))\n-            )\n+            return self._has_any_perms_for_target_model(request, ['change', 'view'])\n         return super().has_view_permission(request)\n \n \n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 74, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 74, "steps": 8}], "ms": 28384}
{"instance_id": "django__django-11179", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py\nindex 92fe4affb9..3a462f1c4c 100644\n--- a/django/db/models/deletion.py\n+++ b/django/db/models/deletion.py\n@@ -277,6 +277,7 @@ class Collector:\n             if self.can_fast_delete(instance):\n                 with transaction.mark_for_rollback_on_error():\n                     count = sql.DeleteQuery(model).delete_batch([instance.pk], self.using)\n+                setattr(instance, model._meta.pk.attname, None)\n                 return count, {model._meta.label: count}\n \n         with transaction.atomic(using=self.using, savepoint=False):\n", "model": "claude-sonnet-5-5", "steps": 4, "finished": true, "patch_lines": 12, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 12, "steps": 4}], "ms": 11751}
{"instance_id": "django__django-11206", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py\nindex 88b35fc435..961a60e37d 100644\n--- a/django/utils/numberformat.py\n+++ b/django/utils/numberformat.py\n@@ -27,6 +27,14 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='',\n     # sign\n     sign = ''\n     if isinstance(number, Decimal):\n+\n+        if decimal_pos is not None:\n+            # If the provided number is too small to affect any of the visible\n+            # decimal places, consider it equal to '0'.\n+            cutoff = Decimal('0.' + '1'.rjust(decimal_pos, '0'))\n+            if abs(number) < cutoff:\n+                number = Decimal('0')\n+\n         # Format values with more than 200 digits (an arbitrary cutoff) using\n         # scientific notation to avoid high memory usage in {:f}'.format().\n         _, digits, exponent = number.as_tuple()\n", "model": "claude-sonnet-5-5", "steps": 2, "finished": true, "patch_lines": 19, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 19, "steps": 2}], "ms": 10948}
{"instance_id": "django__django-11211", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py\nindex ed98ecb48c..6098b71a39 100644\n--- a/django/contrib/contenttypes/fields.py\n+++ b/django/contrib/contenttypes/fields.py\n@@ -202,7 +202,7 @@ class GenericForeignKey(FieldCacheMixin):\n             else:\n                 model = self.get_content_type(id=ct_id,\n                                               using=obj._state.db).model_class()\n-                return (model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),\n+                return (model._meta.pk.to_python(getattr(obj, self.fk_field)),\n                         model)\n \n         return (\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 13, "steps": 6}], "ms": 19766}
{"instance_id": "django__django-11239", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py\nindex cf4df76882..0efe0d47f0 100644\n--- a/django/db/backends/postgresql/client.py\n+++ b/django/db/backends/postgresql/client.py\n@@ -17,6 +17,10 @@ class DatabaseClient(BaseDatabaseClient):\n         dbname = conn_params.get('database', '')\n         user = conn_params.get('user', '')\n         passwd = conn_params.get('password', '')\n+        sslmode = conn_params.get('sslmode', '')\n+        sslrootcert = conn_params.get('sslrootcert', '')\n+        sslcert = conn_params.get('sslcert', '')\n+        sslkey = conn_params.get('sslkey', '')\n \n         if user:\n             args += ['-U', user]\n@@ -30,6 +34,14 @@ class DatabaseClient(BaseDatabaseClient):\n         subprocess_env = os.environ.copy()\n         if passwd:\n             subprocess_env['PGPASSWORD'] = str(passwd)\n+        if sslmode:\n+            subprocess_env['PGSSLMODE'] = str(sslmode)\n+        if sslrootcert:\n+            subprocess_env['PGSSLROOTCERT'] = str(sslrootcert)\n+        if sslcert:\n+            subprocess_env['PGSSLCERT'] = str(sslcert)\n+        if sslkey:\n+            subprocess_env['PGSSLKEY'] = str(sslkey)\n         try:\n             # Allow SIGINT to pass to psql to abort queries.\n             signal.signal(signal.SIGINT, signal.SIG_IGN)\n", "model": "claude-sonnet-5-5", "steps": 3, "finished": true, "patch_lines": 30, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 30, "steps": 3}], "ms": 9923}
