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:
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")