Opened 9 years ago

Closed 8 years ago

#2416 closed enhancement (fixed)

Auth should use primary key rather than 'id' when referencing user

Reported by: dp_wiz Owned by: nobody
Component: Contrib apps Version: master
Severity: normal Keywords:
Cc: aenor.realm@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

Got two problems on using profile system:

1) user.get_profile() fails with "AttributeError: NoneType has no _default_manager" when using shell in
/usr/local/src/django_trunk/django/contrib/auth:

self._profile_cache = model._default_manager.get(useridexact=self.id)

Error is gone after execution of models.get_models()

2) i have profile class with no 'id' field, but 'user_idnr' as primary key.
But useridexact is hardcoded in the same line above.

Attachments (1)

2416.diff (737 bytes) - added by wiz 9 years ago.
my workover for both issues

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by wiz

my workover for both issues

comment:1 Changed 9 years ago by anonymous

  • Summary changed from Auth Profile not working problems to Auth Profile issues

comment:2 Changed 9 years ago by anonymous

  • Summary changed from Auth Profile issues to [patch] Auth Profile issues

comment:3 Changed 9 years ago by mtredinnick

  • Summary changed from [patch] Auth Profile issues to Auth Profile issues

The second part of this patch is not correct. That queryset is referring to the User model, not the Profile model, so user__id__exact is correct (it is finding the profile that belongs to the given user id).

For the first part of the problem, I don't really understand what you are doing to see the problem. Can you paste a few commands I can run to replicate it, please? I want to make sure we are fixing the real problem, not just covering up the cause.

Removing the patch keyword for now, since it can't be applied as is.

comment:4 Changed 9 years ago by mtredinnick

It just occurred to me that the first part of this ticket is probably the problem from #2684.

comment:5 Changed 8 years ago by SmileyChris

  • Patch needs improvement set
  • Summary changed from Auth Profile issues to Auth should use primary key rather than 'id' when referencing user
  • Triage Stage changed from Unreviewed to Accepted

I'll change the summary to reference the second part of this ticket since it does look like #2684 handles part 1.

I think that this would solve it, but haven't tested it:
self._profile_cache = model._default_manager.get(user=self)

comment:6 Changed 8 years ago by mtredinnick

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

I'm going to claim that this is a non-bug. The first paragraph of comment 3, above, is still correct.

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