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

1# Generated by Django 3.2.5 on 2021-10-14 06:32 

2 

3import re 

4 

5from django.db import migrations 

6 

7 

8def build_refs(apps, schema_editor): 

9 """ 

10 Rebuild the integer "reference fields" for existing Build objects 

11 """ 

12 

13 BuildOrder = apps.get_model('build', 'build') 

14 

15 for build in BuildOrder.objects.all(): 15 ↛ 17line 15 didn't jump to line 17 because the loop on line 15 never started

16 

17 ref = 0 

18 

19 result = re.match(r"^(\d+)", build.reference) 

20 

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 

26 

27 # Clip integer value to ensure it does not overflow database field 

28 if ref > 0x7fffffff: 

29 ref = 0x7fffffff 

30 

31 build.reference_int = ref 

32 build.save() 

33 

34 

35class Migration(migrations.Migration): 

36 

37 atomic = False 

38 

39 dependencies = [ 

40 ('build', '0031_build_reference_int'), 

41 ] 

42 

43 operations = [ 

44 migrations.RunPython( 

45 build_refs, 

46 reverse_code=migrations.RunPython.noop 

47 ) 

48 ]