Unable to set PK for custom user model
|Reported by:||markteisman@…||Owned by:||nobody|
|Severity:||Normal||Keywords:||PK Primary Key Custom User|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Description (last modified by claudep)
I've written a custom user model, and wished to set a field as the primary key. See the example below.
class User(AbstractBaseUser): email = models.EmailField(_('email'), max_length=75, unique=True, primary_key=True) USERNAME_FIELD = 'email' ...
Registering the user works fine, but when I authenticate the user using django.contrib.auth.views.login, I get an error stating that the 'User' object has no attribute 'id'.
I discussed this on IRC, where it was suggested to report this as a bug. We believe it is desirable to use .pk instead, for reasons related to portability.
A quick search has shown that there are 12 instances of 'user.id'.
Here's a summary of the error report:
Exception Type: AttributeError Exception Value: 'User' object has no attribute 'id' Exception Location: <path>/lib/python2.6/site-packages/django/contrib/auth/__init__.py in login, line 84 Python Executable: <path>/bin/python Python Version: 2.6.5
Change History (8)
comment:1 Changed 3 years ago by claudep
- Description modified (diff)
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 3 years ago by claudep
- Easy pickings set
- Triage Stage changed from Unreviewed to Accepted
Changed 3 years ago by claudep
comment:6 Changed 3 years ago by Claude Paroz <claude@…>
- Resolution set to fixed
- Status changed from new to closed