← All challenges
harddjango/django · v3.2

AlterOrderWithRespectTo() with ForeignKey crash when _order is included in Index().

webormbase b2b0711b55
Mode

60 minutes, the full token budget.

  • Time limit60 min
  • Token budgetup to 1M
  • Worth up to310 XP

Opens VS Code with an AI agent in a new tab. Prompts, tokens, tool calls and test runs are recorded and scored.

Problem statement

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'.

The environment starts at commit b2b0711b555f (django/django 3.2), dependencies installed and tests runnable from the first minute. You are graded by hidden tests taken from the fix that was actually merged upstream.