Opened 13 years ago
Closed 13 years ago
#16615 closed Bug (needsinfo)
UserChangeForm does not handle username changes well
Reported by: | Lacrymology | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using UserChangeForm to change the logged in user's username, it changes the instance's username (and any other data changed) to the requested value until the next request. This doesn't change the database, but it does make the response template use the wrong username on this request's render.
this is caused by ModelForm's build_instance when the form was created with an instance
kwarg, which is called before checking for uniqueness.
In general, it doesn't seem that the UserChangeForm handles failure very well when the instance kwarg is set.
If you don't call
save()
, the new values won't be saved in the database. Still, the current request will use the new username, because it's saved in the copy of the User object held in memory. I guess that what you call the "wrong" username.You aren't really describing a bug in Django. Could you be more specific, and provide simple instructions to trigger the bug? Maybe write a test case demonstrating it?