Code

Opened 3 years ago

Closed 3 years ago

#15268 closed (invalid)

User.objects.get_or_create has inconsistent behavior

Reported by: w004dal Owned by: nobody
Component: contrib.auth Version: 1.2
Severity: Keywords:
Cc: w004dal@…, w004dal Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When I use User.objects.get_or_create(username=u, password=p) it should be syntactic sugar to:

try:

u = User.objects.get(username=u)
assert u.password == p
return u

except User.DoesNotExist:

return User.objects.create_user(username=u, password=p, email=foo)

Additionally:

User.objects.get_or_create(username=u, password=p) raises a database inconsistency error if 'u' exists with encrypted password 'p'.

If 'u' does not exist in the database, the password is stored in clear text.

This issue seems to coincide with an authentication issue in the administration console. When an admin tries to change the user's password, it is stored in clear text.

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by w004dal

  • Cc w004dal added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by russellm

This isn't inconsistent at all. You create an object with create(). get_or_create() falls back to create().

The User manager provides a helper functions, including 'create_user', to simplify the process of creating a new user -- but to me, that doesn't mean that create_user should be the default used by get_or_create.

comment:3 Changed 3 years ago by russellm

  • Resolution set to invalid
  • Status changed from new to closed

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.