Code

Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#20394 closed Cleanup/optimization (fixed)

parameter ``user_id`` of the custom ``get_user`` method has to be the pk of User

Reported by: zhongqi90@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords: misleading, ambiguous, authentication
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

parameter user_id of the custom get_user method has to be the pk of User, while the documentation's statement is quite misleading.

The original documentation says "The get_user method takes a user_id – which could be a username, database ID or whatever – and returns a User object." https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#writing-an-authentication-backend

It misguides many newbies like me.

In fact, the login function in contrib.auth stores user.pk in session, then get_user function in contrib.auth gets user.pk in session and then passes it to your custom get_user as user_id.

Which means, user_id parameter in your custom get_user has to be the primary key of User object, too.

Attachments (0)

Change History (3)

comment:1 Changed 11 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 11 months ago by Tim Graham <timograham@…>

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

In 1708c8afb6f07417da192bae93a828065858fb3c:

Merge pull request #1053 from makto/patch-1

Fixed #20394 - Clarified argument of get_user in docs

comment:3 Changed 11 months ago by Tim Graham <timograham@…>

In be6e7ff6ebda7acca71e32c2e7890c62e98ba81a:

[1.5.x] Fixed #20394 - Clarified argument of get_user in docs

Backport of 1172bef998 from master.

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.