Repository: saleor/saleor

Issue:
Localization of duplicate email account doesn't make sense
I saw this weird thing in post production when I was creating a customer account that was already registered.

![](https://i.imgur.com/DIT6uHC.png)

![](https://i.imgur.com/SXlwkvt.png)

---

Edit: note, the untranslated string is ` User with this Email already exists. `

---

I'm not quite sure how to explain this, it doesn't make sense in other language, but make sense in English. It's understandable for a French or a Polish for example but doesn't make real sense it shouldn't be that way, it looks like a debug string (as a dev).

I will wait to hear back from you. I also know it's not from your side, so I'm not quite sure of what you can do about this.

The error is generated by `django.db.models.base.Model#unique_error_message` (sourcing from `django.forms.models.BaseModelForm#_post_clean`).
```python
    def unique_error_message(self, model_class, unique_check):
        opts = model_class._meta

        params = {
            'model': self,
            'model_class': model_class,
            'model_name': capfirst(opts.verbose_name),
            'unique_check': unique_check,
        }

        # A unique field
        if len(unique_check) == 1:
            field = opts.get_field(unique_check[0])
            params['field_label'] = capfirst(field.verbose_name)
            return ValidationError(
                message=field.error_messages['unique'],
                code='unique',
                params=params,
            )

        # unique_together
        else:
            field_labels = [capfirst(opts.get_field(f).verbose_name) for f in unique_check]
            params['field_labels'] = get_text_list(field_labels, _('and'))
            return ValidationError(
                message=_("%(model_name)s with this %(field_labels)s already exists."),
                code='unique_together',
                params=params,
            )
            # ^^^^^^
```


Discussion:
I agree this message is not very user-friendly. Fortunately, we are able to override it in the `SignupForm` like this:
```python
class SignupForm(forms.ModelForm):
    password = forms.CharField(
        widget=forms.PasswordInput)
    email = forms.EmailField(
        error_messages={
            'unique': pgettext_lazy(
                'Registration error',
                'This email has already been registered.')})
```
What do you think?
Nothing else to say other than perfect! :+1: 
I'll open a PR.

Resolving patch:
diff --git a/saleor/account/forms.py b/saleor/account/forms.py
--- a/saleor/account/forms.py
+++ b/saleor/account/forms.py
@@ -70,6 +70,11 @@ def __init__(self, request=None, *args, **kwargs):
 class SignupForm(forms.ModelForm):
     password = forms.CharField(
         widget=forms.PasswordInput)
+    email = forms.EmailField(
+        error_messages={
+            'unique': pgettext_lazy(
+                'Registration error',
+                'This email has already been registered.')})
 
     class Meta:
         model = User


Test patch:
diff --git a/tests/test_registration.py b/tests/test_registration.py
--- a/tests/test_registration.py
+++ b/tests/test_registration.py
@@ -96,8 +96,7 @@ def test_signup_form_user_exists(customer_user):
     data = {'email': customer_user.email, 'password': 'password'}
     form = SignupForm(data)
     assert not form.is_valid()
-    error_message = 'User with this Email already exists.'
-    assert form.errors['email'] == [error_message]
+    assert form.errors['email']
 
 
 def test_signup_view_create_user(client, db):