Migration fix: delete TurningPoints w/ project=None

Fix #155
This commit is contained in:
Klaas van Schelven
2025-07-17 14:36:10 +02:00
parent 2ddea33d41
commit fd80eff7ca
2 changed files with 20 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
# Changes
## 1.7.3 (17 July 2025)
Migration fix: delete TurningPoints w/ project=None (Fix #155)
## 1.7.2 (17 July 2025)
Various fixes:

View File

@@ -2,6 +2,18 @@ from django.db import migrations, models
import django.db.models.deletion
def delete_turningpoints_pointing_to_null_project(apps, schema_editor):
# In 0023_turningpoint_set_project, we set the project field for TurningPoint to the associated Issue's project.
# _However_, at that point in time in our migration-history, Issue's project field was still nullable, and the big
# null-project-fk-deleting migration (projects/migrations/0013_delete_objects_pointing_to_null_project.py) is _sure_
# not to have run yet (it depends on the present migration). (it wouldn't delete TurningPoints anyway, but it would
# delete project-less Issues). Anyway, we just take care of the TurningPoints here (that's ok as per 0013_delete_...
# logic, i.e. no-project means no way to access) and it's also possible since they are on the edge of our object
# graph.
TurningPoint = apps.get_model("issues", "TurningPoint")
TurningPoint.objects.filter(project__isnull=True).delete()
class Migration(migrations.Migration):
dependencies = [
@@ -10,6 +22,10 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(
delete_turningpoints_pointing_to_null_project,
migrations.RunPython.noop,
),
migrations.AlterField(
model_name="turningpoint",
name="project",