Skip to content

Commit

Permalink
Fix BuildItem with empty BuildLine reference (inventree#7178)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored and martonmiklos committed May 8, 2024
1 parent 7ee98a6 commit 23ef266
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.12 on 2024-05-08 01:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('build', '0048_build_project_code'),
]

operations = [
migrations.AlterField(
model_name='builditem',
name='build_line',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='allocations', to='build.buildline'),
),
]
26 changes: 26 additions & 0 deletions src/backend/InvenTree/build/migrations/0050_auto_20240508_0138.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.12 on 2024-05-08 01:38

from django.db import migrations


def forward(apps, schema_editor):
"""Find and delete any BuildItem instances which have a null BuildLine field."""

BuildItem = apps.get_model('build', 'BuildItem')

items = BuildItem.objects.filter(build_line=None)

if items.count() > 0:
print(f"Deleting {items.count()} BuildItem objects with null BuildLine field")
items.delete()


class Migration(migrations.Migration):

dependencies = [
('build', '0049_alter_builditem_build_line'),
]

operations = [
migrations.RunPython(forward, reverse_code=migrations.RunPython.noop),
]
2 changes: 1 addition & 1 deletion src/backend/InvenTree/build/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ def complete_allocation(self, user, notes=''):

build_line = models.ForeignKey(
BuildLine,
on_delete=models.SET_NULL, null=True,
on_delete=models.CASCADE, null=True,
related_name='allocations',
)

Expand Down

0 comments on commit 23ef266

Please sign in to comment.