Coverage for src/backend/InvenTree/build/migrations/0032_auto_20211014_0632.py: 38%
20 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1# Generated by Django 3.2.5 on 2021-10-14 06:32
3import re
5from django.db import migrations
8def build_refs(apps, schema_editor):
9 """
10 Rebuild the integer "reference fields" for existing Build objects
11 """
13 BuildOrder = apps.get_model('build', 'build')
15 for build in BuildOrder.objects.all(): 15 ↛ 17line 15 didn't jump to line 17 because the loop on line 15 never started
17 ref = 0
19 result = re.match(r"^(\d+)", build.reference)
21 if result and len(result.groups()) == 1:
22 try:
23 ref = int(result.groups()[0])
24 except Exception: # pragma: no cover
25 ref = 0
27 # Clip integer value to ensure it does not overflow database field
28 if ref > 0x7fffffff:
29 ref = 0x7fffffff
31 build.reference_int = ref
32 build.save()
35class Migration(migrations.Migration):
37 atomic = False
39 dependencies = [
40 ('build', '0031_build_reference_int'),
41 ]
43 operations = [
44 migrations.RunPython(
45 build_refs,
46 reverse_code=migrations.RunPython.noop
47 )
48 ]