Opened 7 years ago

Closed 7 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:


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


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)


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.

Change History (3)

comment:1 Changed 7 years ago by w004dal

Cc: w004dal added

comment:2 Changed 7 years ago by Russell Keith-Magee

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 7 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top