New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #26719 -- Normalized email in AbstractUser.clean(). #6788
Conversation
I wonder what's the more correct way to do that, the |
@@ -145,7 +145,6 @@ def _create_user(self, username, email, password, **extra_fields): | |||
if not username: | |||
raise ValueError('The given username must be set') | |||
email = self.normalize_email(email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this line should also disappear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Yes, thanks a lot. Somehow I forgot to delete that line after several double checks 😞
Normalizing in |
@@ -361,6 +360,13 @@ def email_user(self, subject, message, from_email=None, **kwargs): | |||
""" | |||
send_mail(subject, message, from_email, [self.email], **kwargs) | |||
|
|||
def save(self, *args, **kwargs): | |||
if self.email: | |||
self.email = UserManager.normalize_email(self.email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to account for the possibility of a custom manager with something like self.__class__._default_manager.normalize_email
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion. It looks better to me, will fix this in the next commit
Sure, in my local patch, I'm calling |
FYI here's my current local patch: https://gist.github.com/claudep/78e3661224a9b1767b8b0ea3b8ac8e9b |
@claudep 👍 Thanks for the patch. I will update the code with normalization happen in |
Please let me know if you have time to work on this in the next 8 hours. If not, I can pick it up since we're trying to get the beta release out today. Thanks! |
@timgraham Thanks, I am working on it, will push the code soon |
@@ -111,6 +111,7 @@ def clean_password2(self): | |||
def save(self, commit=True): | |||
user = super(UserCreationForm, self).save(commit=False) | |||
user.set_password(self.cleaned_data["password1"]) | |||
user.clean() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't expect this would be needed since Model.clean()
is called as part of ModelForm
validation (the test passes with this commented out). Was it just an oversight on your part?
I'll open a PR to your branch for these changes. |
Edits at tamhuynhit#1. I think this is good to go after that although if @claudep can take a look, that would be welcome. |
PR is merged. Thanks for helping me on this @timgraham @claudep |
Looks better and better! The remaining questions for me:
|
@claudep About the first question, I think you make sense to have that concern since the current code to call def get_username(self):
return getattr(self, self.USERNAME_FIELD, '') Move them up to |
I think I'll do a separate PR to make the changes for username. Then we can rebase this PR and make the changes for email which is more complicated with respect to backwards-compatibility if we want to move the manager method. Changing how email is normalized also isn't a release blocker for 1.10. |
Patch for username changes only: #6819 |
With the other patch merged, you can either rebase your branch and force push, or open a new PR to continue the changes for normalizing email. |
@@ -890,6 +890,11 @@ Miscellaneous | |||
* If you subclass ``AbstractBaseUser`` and override ``clean()``, be sure it | |||
calls ``super()``. :meth:`.AbstractBaseUser.normalize_username` is called in | |||
a new :meth:`.AbstractBaseUser.clean` method. | |||
* If you subclass ``AbstractUser`` and override ``clean()``, be sure it calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're targeting 1.11 for this change. This only needs to mention email now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to the 1.11 release notes and also update the versionadded annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've moved them to 1.11, you can check again if I didn't make it right
You can squash commits when updating too. |
caa6ab7
to
ebb2487
Compare
merged in 09119df, thanks! |
https://code.djangoproject.com/ticket/26719