⚒️ Generated with [Fabro](https://fabro.sh)
This commit is contained in:
Fabro 2026-03-16 01:32:33 -04:00
parent 6cb40f39a4
commit ceb3352bc8
3 changed files with 129 additions and 0 deletions

111
graph.fabro Normal file
View file

@ -0,0 +1,111 @@
digraph SWEBench {
graph [goal="AlterOrderWithRespectTo() with ForeignKey crash when _order is included in Index().
Description
class Meta:
db_table = 'look_image'
order_with_respect_to = 'look'
indexes = [
models.Index(fields=['look', '_order']),
models.Index(fields=['created_at']),
models.Index(fields=['updated_at']),
]
migrations.CreateModel(
name='LookImage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('look', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='posts.Look', verbose_name='LOOK')),
('image_url', models.URLField(blank=True, max_length=10000, null=True)),
('image', models.ImageField(max_length=2000, upload_to='')),
('deleted', models.DateTimeField(editable=False, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.AddIndex(
model_name='lookimage',
index=models.Index(fields=['look', '_order'], name='look_image_look_id_eaff30_idx'),
),
migrations.AddIndex(
model_name='lookimage',
index=models.Index(fields=['created_at'], name='look_image_created_f746cf_idx'),
),
migrations.AddIndex(
model_name='lookimage',
index=models.Index(fields=['updated_at'], name='look_image_updated_aceaf9_idx'),
),
migrations.AlterOrderWithRespectTo(
name='lookimage',
order_with_respect_to='look',
),
I added orders_with_respect_to in new model class's Meta class and also made index for '_order' field by combining with other field. And a new migration file based on the model looks like the code above.
The problem is operation AlterOrderWithRespectTo after AddIndex of '_order' raising error because '_order' field had not been created yet.
It seems to be AlterOrderWithRespectTo has to proceed before AddIndex of '_order'.
## Additional Context
Thanks for this report. IMO order_with_respect_to should be included in CreateModel()'s options, I'm not sure why it is in a separate operation when it refers to a ForeignKey.
I reproduced the issue adding order_with_respect_to and indexes = [models.Index(fields='_order')] at the same time to an existent model. class Meta: order_with_respect_to = 'foo' indexes = [models.Index(fields='_order')] A small broken test: https://github.com/iurisilvio/django/commit/5c6504e67f1d2749efd13daca440dfa54708a4b2 I'll try to fix the issue, but I'm not sure the way to fix it. Can we reorder autodetected migrations?
PR"]
rankdir=LR
start [shape=Mdiamond]
exit [shape=Msquare]
setup [label="Setup", shape=parallelogram, script="git clone https://github.com/django/django.git . && git checkout b2b0711b555fa292751763c2df4fe577c396f265 && python -m pip install -e ."]
solve [label="Solve", prompt="Fix this GitHub issue in the repository. Make the minimal code change needed.\n\nAlterOrderWithRespectTo() with ForeignKey crash when _order is included in Index().
Description
class Meta:
db_table = 'look_image'
order_with_respect_to = 'look'
indexes = [
models.Index(fields=['look', '_order']),
models.Index(fields=['created_at']),
models.Index(fields=['updated_at']),
]
migrations.CreateModel(
name='LookImage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('look', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='posts.Look', verbose_name='LOOK')),
('image_url', models.URLField(blank=True, max_length=10000, null=True)),
('image', models.ImageField(max_length=2000, upload_to='')),
('deleted', models.DateTimeField(editable=False, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.AddIndex(
model_name='lookimage',
index=models.Index(fields=['look', '_order'], name='look_image_look_id_eaff30_idx'),
),
migrations.AddIndex(
model_name='lookimage',
index=models.Index(fields=['created_at'], name='look_image_created_f746cf_idx'),
),
migrations.AddIndex(
model_name='lookimage',
index=models.Index(fields=['updated_at'], name='look_image_updated_aceaf9_idx'),
),
migrations.AlterOrderWithRespectTo(
name='lookimage',
order_with_respect_to='look',
),
I added orders_with_respect_to in new model class's Meta class and also made index for '_order' field by combining with other field. And a new migration file based on the model looks like the code above.
The problem is operation AlterOrderWithRespectTo after AddIndex of '_order' raising error because '_order' field had not been created yet.
It seems to be AlterOrderWithRespectTo has to proceed before AddIndex of '_order'.
## Additional Context
Thanks for this report. IMO order_with_respect_to should be included in CreateModel()'s options, I'm not sure why it is in a separate operation when it refers to a ForeignKey.
I reproduced the issue adding order_with_respect_to and indexes = [models.Index(fields='_order')] at the same time to an existent model. class Meta: order_with_respect_to = 'foo' indexes = [models.Index(fields='_order')] A small broken test: https://github.com/iurisilvio/django/commit/5c6504e67f1d2749efd13daca440dfa54708a4b2 I'll try to fix the issue, but I'm not sure the way to fix it. Can we reorder autodetected migrations?
PR"]
extract_patch [label="Extract Patch", shape=parallelogram, script="git diff"]
start -> setup -> solve -> extract_patch -> exit
}

13
manifest.json Normal file
View file

@ -0,0 +1,13 @@
{
"run_id": "01KKTJ36SCY6TBFTKJNR8HV875",
"workflow_name": "SWEBench",
"goal": "AlterOrderWithRespectTo() with ForeignKey crash when _order is included in Index().\nDescription\n\t\n\tclass Meta:\n\t\tdb_table = 'look_image'\n\t\torder_with_respect_to = 'look'\n\t\tindexes = [\n\t\t\tmodels.Index(fields=['look', '_order']),\n\t\t\tmodels.Index(fields=['created_at']),\n\t\t\tmodels.Index(fields=['updated_at']),\n\t\t]\nmigrations.CreateModel(\n\t\t\tname='LookImage',\n\t\t\tfields=[\n\t\t\t\t('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),\n\t\t\t\t('look', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images', to='posts.Look', verbose_name='LOOK')),\n\t\t\t\t('image_url', models.URLField(blank=True, max_length=10000, null=True)),\n\t\t\t\t('image', models.ImageField(max_length=2000, upload_to='')),\n\t\t\t\t('deleted', models.DateTimeField(editable=False, null=True)),\n\t\t\t\t('created_at', models.DateTimeField(auto_now_add=True)),\n\t\t\t\t('updated_at', models.DateTimeField(auto_now=True)),\n\t\t\t],\n\t\t),\n\t\tmigrations.AddIndex(\n\t\t\tmodel_name='lookimage',\n\t\t\tindex=models.Index(fields=['look', '_order'], name='look_image_look_id_eaff30_idx'),\n\t\t),\n\t\tmigrations.AddIndex(\n\t\t\tmodel_name='lookimage',\n\t\t\tindex=models.Index(fields=['created_at'], name='look_image_created_f746cf_idx'),\n\t\t),\n\t\tmigrations.AddIndex(\n\t\t\tmodel_name='lookimage',\n\t\t\tindex=models.Index(fields=['updated_at'], name='look_image_updated_aceaf9_idx'),\n\t\t),\n\t\tmigrations.AlterOrderWithRespectTo(\n\t\t\tname='lookimage',\n\t\t\torder_with_respect_to='look',\n\t\t),\nI added orders_with_respect_to in new model class's Meta class and also made index for '_order' field by combining with other field. And a new migration file based on the model looks like the code above.\nThe problem is operation AlterOrderWithRespectTo after AddIndex of '_order' raising error because '_order' field had not been created yet.\nIt seems to be AlterOrderWithRespectTo has to proceed before AddIndex of '_order'.\n\n\n\n## Additional Context\n\nThanks for this report. IMO order_with_respect_to should be included in CreateModel()'s options, I'm not sure why it is in a separate operation when it refers to a ForeignKey.\nI reproduced the issue adding order_with_respect_to and indexes = [models.Index(fields='_order')] at the same time to an existent model. class Meta: order_with_respect_to = 'foo' indexes = [models.Index(fields='_order')] A small broken test: https://github.com/iurisilvio/django/commit/5c6504e67f1d2749efd13daca440dfa54708a4b2 I'll try to fix the issue, but I'm not sure the way to fix it. Can we reorder autodetected migrations?\nPR",
"start_time": "2026-03-16T05:32:33.870119Z",
"node_count": 5,
"edge_count": 4,
"run_branch": "fabro/run/01KKTJ36SCY6TBFTKJNR8HV875",
"base_sha": "470fcfe1200b2102c0cdf91c73b0ed8d925f258a",
"base_branch": "main",
"workflow_slug": "django__django-13265",
"host_repo_path": "/Users/bhelmkamp/p/fabro-sh/fabro/evals/swe-bench/results/haiku-baseline/runs/django__django-13265"
}

5
sandbox.json Normal file
View file

@ -0,0 +1,5 @@
{
"provider": "daytona",
"working_directory": "/home/daytona/workspace",
"identifier": "fabro-01KKTJ36SCY6TBFTKJNR8HV875"
}