Skip to content

Commit e2c753f

Browse files
committed
fixup! feat: Change queries to use lab column information
Rename Builds/Tests FK field from lab to lab_id so lab is free for annotated lab names without conflicting with the ORM relation. Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
1 parent 286950c commit e2c753f

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import django.db.models.deletion
2+
from django.db import migrations, models
3+
4+
5+
class Migration(migrations.Migration):
6+
dependencies = [
7+
("kernelCI_app", "0019_labs_builds_lab_tests_lab"),
8+
]
9+
10+
operations = [
11+
migrations.RenameField(
12+
model_name="builds",
13+
old_name="lab",
14+
new_name="lab_id",
15+
),
16+
migrations.RenameField(
17+
model_name="tests",
18+
old_name="lab",
19+
new_name="lab_id",
20+
),
21+
migrations.AlterField(
22+
model_name="builds",
23+
name="lab_id",
24+
field=models.ForeignKey(
25+
db_column="lab_id",
26+
db_constraint=False,
27+
null=True,
28+
on_delete=django.db.models.deletion.DO_NOTHING,
29+
to="kernelCI_app.labs",
30+
),
31+
),
32+
migrations.AlterField(
33+
model_name="tests",
34+
name="lab_id",
35+
field=models.ForeignKey(
36+
db_column="lab_id",
37+
db_constraint=False,
38+
null=True,
39+
on_delete=django.db.models.deletion.DO_NOTHING,
40+
to="kernelCI_app.labs",
41+
),
42+
),
43+
]

backend/kernelCI_app/models.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ class Builds(models.Model):
132132
log_url = models.TextField(blank=True, null=True)
133133
log_excerpt = models.CharField(max_length=16384, blank=True, null=True)
134134
misc = models.JSONField(blank=True, null=True)
135-
lab = models.ForeignKey(
136-
Labs, db_constraint=False, null=True, on_delete=models.DO_NOTHING
135+
lab_id = models.ForeignKey(
136+
Labs,
137+
db_column="lab_id",
138+
db_constraint=False,
139+
null=True,
140+
on_delete=models.DO_NOTHING,
137141
)
138142
status = models.CharField(
139143
max_length=10, choices=StatusChoices.choices, blank=True, null=True
@@ -193,8 +197,12 @@ class UnitPrefix(models.TextChoices):
193197
input_files = models.JSONField(blank=True, null=True)
194198
output_files = models.JSONField(blank=True, null=True)
195199
misc = models.JSONField(blank=True, null=True)
196-
lab = models.ForeignKey(
197-
Labs, db_constraint=False, null=True, on_delete=models.DO_NOTHING
200+
lab_id = models.ForeignKey(
201+
Labs,
202+
db_column="lab_id",
203+
db_constraint=False,
204+
null=True,
205+
on_delete=models.DO_NOTHING,
198206
)
199207
number_value = models.FloatField(blank=True, null=True)
200208
environment_compatible = ArrayField(models.TextField(), blank=True, null=True)

backend/kernelCI_app/queries/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_build_tests(build_id: str) -> Optional[list[dict]]:
5656
# TODO remove misc__runtime fallback after lab backfill
5757
.annotate(
5858
lab=Coalesce(
59-
F("lab__name"),
59+
F("lab_id__name"),
6060
Cast(F("misc__runtime"), output_field=TextField()),
6161
)
6262
)

0 commit comments

Comments
 (0)