From 8268b9b10552bfb42bbf6d99afa562e732aaef1f Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 25 May 2023 10:59:55 +1000 Subject: [PATCH] Fix for data migration (#4892) * Fix for data migration - Catch *all* exceptions - We don't want an unhandled exception to break data migration * Add more exception handling * Fix typo --- .../part/migrations/0109_auto_20230517_1048.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/InvenTree/part/migrations/0109_auto_20230517_1048.py b/InvenTree/part/migrations/0109_auto_20230517_1048.py index 7f5c551830..abb359119b 100644 --- a/InvenTree/part/migrations/0109_auto_20230517_1048.py +++ b/InvenTree/part/migrations/0109_auto_20230517_1048.py @@ -41,7 +41,7 @@ def update_template_units(apps, schema_editor): try: ureg.Unit(template.units) continue - except pint.errors.UndefinedUnitError: + except Exception: pass # Check a lower-case version @@ -52,7 +52,7 @@ def update_template_units(apps, schema_editor): template.save() n_converted += 1 continue - except pint.errors.UndefinedUnitError: + except Exception: pass found = False @@ -98,12 +98,12 @@ def convert_to_numeric_value(value: str, units: str): try: result = InvenTree.conversion.convert_physical_value(value, units) result = float(result.magnitude) - except (ValidationError, ValueError): + except Exception: pass else: try: result = float(value) - except ValueError: + except Exception: pass return result @@ -122,8 +122,11 @@ def update_parameter_values(apps, schema_editor): # Convert each parameter value to a the specified units for parameter in PartParameter.objects.all(): - parameter.data_numeric = convert_to_numeric_value(parameter.data, parameter.template.units) - parameter.save() + try: + parameter.data_numeric = convert_to_numeric_value(parameter.data, parameter.template.units) + parameter.save() + except Exception: + pass if n_params > 0: print(f"Updated {n_params} parameter values")