Skip to content

Commit

Permalink
Simplify expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandenburgh committed Jan 3, 2025
1 parent 24a5aac commit 2138cef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.4 on 2025-01-03 16:25
# Generated by Django 5.1.4 on 2025-01-03 16:34

from django.db import migrations, models

Expand All @@ -14,36 +14,27 @@ class Migration(migrations.Migration):
name="infrastructure_error",
field=models.GeneratedField(
db_persist=True,
expression=models.Case(
models.When(
expression=models.Q(
models.Q(
("status", "failed"),
models.Q(
models.Q(
("status", "failed"),
models.Q(
models.Q(
(
"error_taxonomy__in",
[
"spack_error",
"build_error",
"concretization_error",
"module_not_found",
],
),
_negated=True,
),
models.Q(
("error_taxonomy", "failed_to_get_specs"),
("job_type", "rebuild-index"),
_negated=True,
),
),
)
(
"error_taxonomy__in",
[
"spack_error",
"build_error",
"concretization_error",
"module_not_found",
],
),
_negated=True,
),
then=models.Value(True),
),
default=models.Value(False),
output_field=models.BooleanField(),
models.Q(
("error_taxonomy", "failed_to_get_specs"),
("job_type", "rebuild-index"),
_negated=True,
),
)
),
help_text='Whether or not this job is an "infrastructure error", or a legitimate CI failure.',
output_field=models.BooleanField(),
Expand Down
41 changes: 16 additions & 25 deletions analytics/analytics/core/models/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,23 @@ class Meta:
infrastructure_error = models.GeneratedField(
output_field=models.BooleanField(),
db_persist=True,
expression=Case(
When(
Q(
Q(status="failed")
& Q(
~Q(
error_taxonomy__in=[
"spack_error",
"build_error",
"concretization_error",
"module_not_found",
]
)
& ~Q(
# This is a special case for the rebuild-index job type.
# If a reindex job fails to get specs, it's not an infrastructure error,
# but only if both those conditions are met.
job_type=JobType.REBUILD_INDEX,
error_taxonomy="failed_to_get_specs",
),
),
),
then=Value(True),
expression=Q(
Q(status="failed")
& ~Q(
error_taxonomy__in=[
"spack_error",
"build_error",
"concretization_error",
"module_not_found",
]
)
& ~Q(
# This is a special case for the rebuild-index job type.
# If a reindex job fails to get specs, it's not an infrastructure error,
# but only if both those conditions are met.
job_type=JobType.REBUILD_INDEX,
error_taxonomy="failed_to_get_specs",
),
default=Value(False),
output_field=models.BooleanField(),
),
help_text='Whether or not this job is an "infrastructure error", or a legitimate CI failure.',
)
Expand Down

0 comments on commit 2138cef

Please sign in to comment.