#19354: Unable to set PK for custom user model
-------------------------------------+-------------------------------------
Reporter: markteisman@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version:
Severity: Normal | 1.5-alpha-1
Keywords: PK Primary Key | Resolution:
Custom User | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> Hello,
> 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
>
> Regards,
> Mark
New description:
Hello,
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
}}}
Regards,
Mark
--
Comment:
Reformatted, please use preview.
--
Ticket URL: <https://code.djangoproject.com/ticket/19354#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.