Short-circuit the custom migration if there are no SupplierPart objects

- This allows the unit testing to run!

(cherry picked from commit f243b567fd)
This commit is contained in:
Oliver Walters 2020-04-13 19:46:57 +10:00
parent 8c55831321
commit 8fa3d77416
2 changed files with 12 additions and 2 deletions

View File

@ -15,8 +15,6 @@ class StatusCode:
Render the value as a label.
"""
print("Rendering:", key, cls.options)
# If the key cannot be found, pass it back
if key not in cls.options.keys():
return key

View File

@ -21,6 +21,12 @@ def reverse_association(apps, schema_editor):
into the 'manufacturer_name' field.
"""
# Exit if there are no SupplierPart objects
# This crucial otherwise the unit test suite fails!
if SupplierPart.objects.count() == 0:
print("No SupplierPart objects - skipping")
return
print("Reversing migration for manufacturer association")
try:
@ -49,6 +55,12 @@ def associate_manufacturers(apps, schema_editor):
It uses fuzzy pattern matching to help the user out as much as possible.
"""
# Exit if there are no SupplierPart objects
# This crucial otherwise the unit test suite fails!
if SupplierPart.objects.count() == 0:
print("No SupplierPart objects - skipping")
return
# Link a 'manufacturer_name' to a 'Company'
links = {}