Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Remove unnecessary reverse function from migration file

akjanik0df9cd38cd24
diff --git a/saleor/userprofile/migrations/0013_auto_20171120_0521.py b/saleor/userprofile/migrations/0013_auto_20171120_0521.py
index 2db4886660..77fd9c9477 100644
--- a/saleor/userprofile/migrations/0013_auto_20171120_0521.py
+++ b/saleor/userprofile/migrations/0013_auto_20171120_0521.py
@@ -3,6 +3,7 @@
from __future__ import unicode_literals
from django.db import migrations
+from phonenumbers.phonenumberutil import NumberParseException
import phonenumber_field.modelfields
import phonenumbers
@@ -11,19 +12,14 @@ def convert_phone_number_to_phonenumberfield(apps, schema_editor):
Address = apps.get_model("userprofile", "Address")
for address in Address.objects.all():
if address.phone:
- phone_number = phonenumbers.parse(address.phone.raw_input,
- address.country.code)
- address.phone = phone_number
- address.save()
-
-
-def convert_phone_number_to_str(apps, schema_editor):
- Address = apps.get_model("userprofile", "Address")
- for address in Address.objects.all():
- if address.phone:
- phone_number = str(address.phone)
- address.phone = phone_number
- address.save()
+ try:
+ phone_number = phonenumbers.parse(
+ address.phone.raw_input,
+ address.country.code)
+ address.phone = phone_number
+ address.save()
+ except NumberParseException:
+ pass
class Migration(migrations.Migration):
@@ -38,6 +34,7 @@ class Migration(migrations.Migration):
name='phone',
field=phonenumber_field.modelfields.PhoneNumberField(blank=True, default='', max_length=128, verbose_name='phone number'),
),
- migrations.RunPython(convert_phone_number_to_phonenumberfield,
- convert_phone_number_to_str),
+ migrations.RunPython(
+ convert_phone_number_to_phonenumberfield,
+ migrations.RunPython.noop),
]