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
This commit is contained in:
Oliver 2023-05-25 10:59:55 +10:00 committed by GitHub
parent fdd4169cd7
commit 8268b9b105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,7 +41,7 @@ def update_template_units(apps, schema_editor):
try: try:
ureg.Unit(template.units) ureg.Unit(template.units)
continue continue
except pint.errors.UndefinedUnitError: except Exception:
pass pass
# Check a lower-case version # Check a lower-case version
@ -52,7 +52,7 @@ def update_template_units(apps, schema_editor):
template.save() template.save()
n_converted += 1 n_converted += 1
continue continue
except pint.errors.UndefinedUnitError: except Exception:
pass pass
found = False found = False
@ -98,12 +98,12 @@ def convert_to_numeric_value(value: str, units: str):
try: try:
result = InvenTree.conversion.convert_physical_value(value, units) result = InvenTree.conversion.convert_physical_value(value, units)
result = float(result.magnitude) result = float(result.magnitude)
except (ValidationError, ValueError): except Exception:
pass pass
else: else:
try: try:
result = float(value) result = float(value)
except ValueError: except Exception:
pass pass
return result return result
@ -122,8 +122,11 @@ def update_parameter_values(apps, schema_editor):
# Convert each parameter value to a the specified units # Convert each parameter value to a the specified units
for parameter in PartParameter.objects.all(): for parameter in PartParameter.objects.all():
parameter.data_numeric = convert_to_numeric_value(parameter.data, parameter.template.units) try:
parameter.save() parameter.data_numeric = convert_to_numeric_value(parameter.data, parameter.template.units)
parameter.save()
except Exception:
pass
if n_params > 0: if n_params > 0:
print(f"Updated {n_params} parameter values") print(f"Updated {n_params} parameter values")