From 91a4c35d3b3c47900ba90d1c5e0912e8bdb04a13 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Tue, 21 Apr 2020 21:38:31 +0200 Subject: [PATCH] Improve comments for User clean methods --- users/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/users/models.py b/users/models.py index 86d2cb5f..4d9e1f20 100755 --- a/users/models.py +++ b/users/models.py @@ -1330,8 +1330,9 @@ class User( raise ValidationError(_("This username is already used.")) def clean_email(self, *args, **kwargs): - # Allow empty emails if the user had an empty email before - if not self.email and (self.__original_email or not self.pk): + # Allow empty emails only if the user had an empty email before + is_created = not self.pk + if not self.email and (self.__original_email or is_created): raise forms.ValidationError( _("Email field cannot be empty.") ) @@ -1346,9 +1347,9 @@ class User( ) def clean(self, *args, **kwargs): - super(User, self).clean(*args, **kwargs) """Check if this pseudo is already used by any mailalias. Better than raising an error in post-save and catching it""" + super(User, self).clean(*args, **kwargs) self.clean_pseudo(*args, **kwargs) self.clean_email(*args, **kwargs)