{"instance_id": "django__django-14915", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/forms/models.py b/django/forms/models.py\nindex 5dcf923c12..bc7e6959e7 100644\n--- a/django/forms/models.py\n+++ b/django/forms/models.py\n@@ -1171,6 +1171,9 @@ class ModelChoiceIteratorValue:\n             other = other.value\n         return self.value == other\n \n+    def __hash__(self):\n+        return hash(self.value)\n+\n \n class ModelChoiceIterator:\n     def __init__(self, field):\n", "model": "claude-sonnet-5-5", "steps": 4, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 14, "steps": 4}], "ms": 11858}
{"instance_id": "django__django-14999", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py\nindex 982816be3a..7d6aac7c75 100644\n--- a/django/db/migrations/operations/models.py\n+++ b/django/db/migrations/operations/models.py\n@@ -320,6 +320,9 @@ class RenameModel(ModelOperation):\n         new_model = to_state.apps.get_model(app_label, self.new_name)\n         if self.allow_migrate_model(schema_editor.connection.alias, new_model):\n             old_model = from_state.apps.get_model(app_label, self.old_name)\n+            # Don't alter when a table name is not changed.\n+            if old_model._meta.db_table == new_model._meta.db_table:\n+                return\n             # Move the main table\n             schema_editor.alter_db_table(\n                 new_model,\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 14, "steps": 9}], "ms": 38144}
{"instance_id": "django__django-15022", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py\nindex 66f3396a6b..c5968a79ed 100644\n--- a/django/contrib/admin/options.py\n+++ b/django/contrib/admin/options.py\n@@ -1031,6 +1031,7 @@ class ModelAdmin(BaseModelAdmin):\n         if search_fields and search_term:\n             orm_lookups = [construct_search(str(search_field))\n                            for search_field in search_fields]\n+            term_queries = []\n             for bit in smart_split(search_term):\n                 if bit.startswith(('\"', \"'\")) and bit[0] == bit[-1]:\n                     bit = unescape_string_literal(bit)\n@@ -1038,7 +1039,8 @@ class ModelAdmin(BaseModelAdmin):\n                     *((orm_lookup, bit) for orm_lookup in orm_lookups),\n                     _connector=models.Q.OR,\n                 )\n-                queryset = queryset.filter(or_queries)\n+                term_queries.append(or_queries)\n+            queryset = queryset.filter(models.Q(*term_queries))\n             may_have_duplicates |= any(\n                 lookup_spawns_duplicates(self.opts, search_spec)\n                 for search_spec in orm_lookups\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 22, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 22, "steps": 9}], "ms": 24250}
{"instance_id": "django__django-15037", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py\nindex f9b4bfb477..982d657191 100644\n--- a/django/core/management/commands/inspectdb.py\n+++ b/django/core/management/commands/inspectdb.py\n@@ -116,10 +116,14 @@ class Command(BaseCommand):\n                         extra_params['unique'] = True\n \n                     if is_relation:\n+                        ref_db_column, ref_db_table = relations[column_name]\n                         if extra_params.pop('unique', False) or extra_params.get('primary_key'):\n                             rel_type = 'OneToOneField'\n                         else:\n                             rel_type = 'ForeignKey'\n+                        ref_pk_column = connection.introspection.get_primary_key_column(cursor, ref_db_table)\n+                        if ref_pk_column and ref_pk_column != ref_db_column:\n+                            extra_params['to_field'] = ref_db_column\n                         rel_to = (\n                             \"self\" if relations[column_name][1] == table_name\n                             else table2model(relations[column_name][1])\n", "model": "claude-sonnet-5-5", "steps": 5, "finished": true, "patch_lines": 19, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 19, "steps": 5}], "ms": 14468}
{"instance_id": "django__django-15098", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py\nindex 7dcc77b46c..f4e35eabbc 100644\n--- a/django/utils/translation/trans_real.py\n+++ b/django/utils/translation/trans_real.py\n@@ -43,7 +43,7 @@ language_code_re = _lazy_re_compile(\n     re.IGNORECASE\n )\n \n-language_code_prefix_re = _lazy_re_compile(r'^/(\\w+([@-]\\w+)?)(/|$)')\n+language_code_prefix_re = _lazy_re_compile(r'^/(\\w+([@-]\\w+){0,2})(/|$)')\n \n \n @receiver(setting_changed)\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 7}], "ms": 17833}
{"instance_id": "django__django-15104", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py\nindex 97977d72ef..bf9c2acd26 100644\n--- a/django/db/migrations/autodetector.py\n+++ b/django/db/migrations/autodetector.py\n@@ -96,7 +96,7 @@ class MigrationAutodetector:\n         for name, field in sorted(fields.items()):\n             deconstruction = self.deep_deconstruct(field)\n             if field.remote_field and field.remote_field.model:\n-                del deconstruction[2]['to']\n+                deconstruction[2].pop('to', None)\n             fields_def.append(deconstruction)\n         return fields_def\n \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": 17506}
{"instance_id": "django__django-15127", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/test/signals.py b/django/test/signals.py\nindex 4d8c43e917..8ad54a7da0 100644\n--- a/django/test/signals.py\n+++ b/django/test/signals.py\n@@ -207,3 +207,11 @@ def user_model_swapped(**kwargs):\n \n             from django.contrib.auth import views\n             views.UserModel = UserModel\n+\n+\n+@receiver(setting_changed)\n+def update_level_tags(*, setting, **kwargs):\n+    if setting == 'MESSAGE_TAGS':\n+        from django.contrib.messages.storage import base\n+        from django.contrib.messages.utils import get_level_tags\n+        base.LEVEL_TAGS = get_level_tags()\n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 16, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 16, "steps": 8}], "ms": 22911}
{"instance_id": "django__django-15128", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py\nindex aaf35ee37c..206a374d42 100644\n--- a/django/db/models/sql/query.py\n+++ b/django/db/models/sql/query.py\n@@ -604,7 +604,9 @@ class Query(BaseExpression):\n             # If the left side of the join was already relabeled, use the\n             # updated alias.\n             join = join.relabeled_clone(change_map)\n-            new_alias = self.join(join, reuse=reuse)\n+            # New aliases must not clash with rhs aliases, otherwise the keys\n+            # and values of change_map could intersect.\n+            new_alias = self.join(join, reuse=reuse, avoid_aliases=rhs.alias_map)\n             if join.join_type == INNER:\n                 rhs_votes.add(new_alias)\n             # We can't reuse the same join again in the query. If we have two\n@@ -745,7 +747,7 @@ class Query(BaseExpression):\n             for model, values in seen.items():\n                 callback(target, model, values)\n \n-    def table_alias(self, table_name, create=False, filtered_relation=None):\n+    def table_alias(self, table_name, create=False, filtered_relation=None, avoid_aliases=()):\n         \"\"\"\n         Return a table alias for the given table_name and whether this is a\n         new alias or not.\n@@ -761,7 +763,13 @@ class Query(BaseExpression):\n \n         # Create a new alias for this table.\n         if alias_list:\n-            alias = '%s%d' % (self.alias_prefix, len(self.alias_map) + 1)\n+            suffix = len(self.alias_map) + 1\n+            alias = '%s%d' % (self.alias_prefix, suffix)\n+            # Don't take an alias listed in avoid_aliases (e.g. the aliases of\n+            # a query being combined into this one).\n+            while alias in avoid_aliases:\n+                suffix += 1\n+                alias = '%s%d' % (self.alias_prefix, suffix)\n             alias_list.append(alias)\n         else:\n             # The first occurrence of a table uses the table name directly.\n@@ -846,6 +854,9 @@ class Query(BaseExpression):\n         relabelling any references to them in select columns and the where\n         clause.\n         \"\"\"\n+        # If keys and values of change_map were to intersect, an alias might be\n+        # updated twice (e.g. T4 -> T5, T5 -> T6, so also T4 -> T6) depending\n+        # on their order in change_map.\n         assert set(change_map).isdisjoint(change_map.values())\n \n         # 1. Update references in \"select\" (normal columns plus aliases),\n@@ -948,7 +959,7 @@ class Query(BaseExpression):\n         \"\"\"\n         return len([1 for count in self.alias_refcount.values() if count])\n \n-    def join(self, join, reuse=None):\n+    def join(self, join, reuse=None, avoid_aliases=()):\n         \"\"\"\n         Return an alias for the 'join', either reusing an existing alias for\n         that join or creating a new one. 'join' is either a base_table_class or\n@@ -976,7 +987,11 @@ class Query(BaseExpression):\n             return reuse_alias\n \n         # No reuse is possible, so we need a new alias.\n-        alias, _ = self.table_alias(join.table_name, create=True, filtered_relation=join.filtered_relation)\n+        alias, _ = self.table_alias(\n+            join.table_name, create=True,\n+            filtered_relation=join.filtered_relation,\n+            avoid_aliases=avoid_aliases,\n+        )\n         if join.join_type:\n             if self.alias_map[join.parent_alias].join_type == LOUTER or join.nullable:\n                 join_type = LOUTER\n", "model": "claude-sonnet-5-5", "steps": 16, "finished": false, "patch_lines": 71, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 71, "steps": 16}], "ms": 79717}
{"instance_id": "django__django-15161", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py\nindex 8642e1f151..fa280ac25b 100644\n--- a/django/db/models/expressions.py\n+++ b/django/db/models/expressions.py\n@@ -390,7 +390,7 @@ class BaseExpression:\n         return sql, params\n \n \n-@deconstructible\n+@deconstructible(path='django.db.models.expressions.Expression')\n class Expression(BaseExpression, Combinable):\n     \"\"\"An expression that can be combined with other expressions.\"\"\"\n \n@@ -651,6 +651,7 @@ class OuterRef(F):\n         return self\n \n \n+@deconstructible(path='django.db.models.Func')\n class Func(SQLiteNumericMixin, Expression):\n     \"\"\"An SQL function call.\"\"\"\n     function = None\n@@ -731,6 +732,7 @@ class Func(SQLiteNumericMixin, Expression):\n         return copy\n \n \n+@deconstructible(path='django.db.models.Value')\n class Value(SQLiteNumericMixin, Expression):\n     \"\"\"Represent a wrapped value as a node within an expression.\"\"\"\n     # Provide a default value for `for_save` in order to allow unresolved\n@@ -912,6 +914,7 @@ class Ref(Expression):\n         return [self]\n \n \n+@deconstructible(path='django.db.models.ExpressionList')\n class ExpressionList(Func):\n     \"\"\"\n     An expression containing multiple expressions. Can be used to provide a\n@@ -953,6 +956,7 @@ class OrderByList(Func):\n         return super().as_sql(*args, **kwargs)\n \n \n+@deconstructible(path='django.db.models.ExpressionWrapper')\n class ExpressionWrapper(SQLiteNumericMixin, Expression):\n     \"\"\"\n     An expression that can wrap another expression so that it can provide\n@@ -985,6 +989,7 @@ class ExpressionWrapper(SQLiteNumericMixin, Expression):\n         return \"{}({})\".format(self.__class__.__name__, self.expression)\n \n \n+@deconstructible(path='django.db.models.When')\n class When(Expression):\n     template = 'WHEN %(condition)s THEN %(result)s'\n     # This isn't a complete conditional expression, must be used in Case().\n@@ -1052,6 +1057,7 @@ class When(Expression):\n         return cols\n \n \n+@deconstructible(path='django.db.models.Case')\n class Case(SQLiteNumericMixin, Expression):\n     \"\"\"\n     An SQL searched CASE expression:\n@@ -1133,6 +1139,7 @@ class Case(SQLiteNumericMixin, Expression):\n         return super().get_group_by_cols(alias)\n \n \n+@deconstructible(path='django.db.models.Subquery')\n class Subquery(BaseExpression, Combinable):\n     \"\"\"\n     An explicit subquery. It may contain OuterRef() references to the outer\n@@ -1190,6 +1197,7 @@ class Subquery(BaseExpression, Combinable):\n         return self.query.get_group_by_cols()\n \n \n+@deconstructible(path='django.db.models.Exists')\n class Exists(Subquery):\n     template = 'EXISTS(%(subquery)s)'\n     output_field = fields.BooleanField()\n@@ -1225,6 +1233,7 @@ class Exists(Subquery):\n         return sql, params\n \n \n+@deconstructible(path='django.db.models.OrderBy')\n class OrderBy(Expression):\n     template = '%(expression)s %(ordering)s'\n     conditional = False\n@@ -1307,6 +1316,7 @@ class OrderBy(Expression):\n         self.descending = True\n \n \n+@deconstructible(path='django.db.models.Window')\n class Window(SQLiteNumericMixin, Expression):\n     template = '%(expression)s OVER (%(window)s)'\n     # Although the main expression may either be an aggregate or an\n@@ -1412,6 +1422,7 @@ class Window(SQLiteNumericMixin, Expression):\n         return []\n \n \n+@deconstructible(path='django.db.models.WindowFrame')\n class WindowFrame(Expression):\n     \"\"\"\n     Model the frame clause in window expressions. There are two types of frame\n@@ -1471,6 +1482,7 @@ class WindowFrame(Expression):\n         raise NotImplementedError('Subclasses must implement window_frame_start_end().')\n \n \n+@deconstructible(path='django.db.models.RowRange')\n class RowRange(WindowFrame):\n     frame_type = 'ROWS'\n \n@@ -1478,6 +1490,7 @@ class RowRange(WindowFrame):\n         return connection.ops.window_frame_rows_start_end(start, end)\n \n \n+@deconstructible(path='django.db.models.ValueRange')\n class ValueRange(WindowFrame):\n     frame_type = 'RANGE'\n \n", "model": "claude-sonnet-5-5", "steps": 16, "finished": false, "patch_lines": 117, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 117, "steps": 16}], "ms": 58317}
{"instance_id": "django__django-15252", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py\nindex 1a37c6b7d0..9952a5ba0d 100644\n--- a/django/db/migrations/recorder.py\n+++ b/django/db/migrations/recorder.py\n@@ -1,5 +1,5 @@\n from django.apps.registry import Apps\n-from django.db import DatabaseError, models\n+from django.db import DatabaseError, models, router\n from django.utils.functional import classproperty\n from django.utils.timezone import now\n \n@@ -50,6 +50,9 @@ class MigrationRecorder:\n     def migration_qs(self):\n         return self.Migration.objects.using(self.connection.alias)\n \n+    def _allow_migrate(self):\n+        return router.allow_migrate_model(self.connection.alias, self.Migration)\n+\n     def has_table(self):\n         \"\"\"Return True if the django_migrations table exists.\"\"\"\n         with self.connection.cursor() as cursor:\n@@ -62,6 +65,9 @@ class MigrationRecorder:\n         # in the codebase.\n         if self.has_table():\n             return\n+        # Don't create the table if the router forbids it on this database.\n+        if not self._allow_migrate():\n+            return\n         # Make the table\n         try:\n             with self.connection.schema_editor() as editor:\n@@ -83,11 +89,15 @@ class MigrationRecorder:\n \n     def record_applied(self, app, name):\n         \"\"\"Record that a migration was applied.\"\"\"\n+        if not self._allow_migrate():\n+            return\n         self.ensure_schema()\n         self.migration_qs.create(app=app, name=name)\n \n     def record_unapplied(self, app, name):\n         \"\"\"Record that a migration was unapplied.\"\"\"\n+        if not self._allow_migrate():\n+            return\n         self.ensure_schema()\n         self.migration_qs.filter(app=app, name=name).delete()\n \n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 47, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 47, "steps": 7}], "ms": 31847}
