Code

Opened 3 years ago

Closed 3 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.

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

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?

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.