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.

Change History (1)

comment:1 by Aymeric Augustin, 13 years ago

Resolution: needsinfo
Status: newclosed

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.

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.

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.

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?

Note: See TracTickets for help on using tickets.
Back to Top