[Django] #24161: Using UUIDField for id of custom User model prevents logging in

24 views
Skip to first unread message

Django

unread,
Jan 16, 2015, 2:18:12 PM1/16/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
----------------------------------+-----------------------
Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+-----------------------
When using the new `UUIDField` in Django 1.8 for the `id` of a custom User
model, a session fails to be created and a `TypeError` exception is thrown
when attempting to log in.

{{{
TypeError at /login/
UUID('314cb5d6-593f-48f5-b1af-fadedde123d3') is not JSON serializable
}}}

Please see the `README.md` file of the attached example project.

--
Ticket URL: <https://code.djangoproject.com/ticket/24161>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 16, 2015, 2:50:31 PM1/16/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
----------------------------------+--------------------------------------

Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by charettes):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Thanks for the example project. Could you also provide the full traceback
please.

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:1>

Django

unread,
Jan 16, 2015, 2:55:51 PM1/16/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
----------------------------------+-------------------------------------

Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------------------
Changes (by charettes):

* stage: Unreviewed => Accepted


Comment:

I guess we should use `user.serializable_value(user._meta.pk.attname)`
[https://github.com/django/django/blob/e8171daf0cd7f0e070395cb4c850c17fea32f11d/django/contrib/auth/__init__.py#L105
here].

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:2>

Django

unread,
Jan 16, 2015, 3:28:29 PM1/16/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
----------------------------------+-------------------------------------

Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------------------

Comment (by jamesbeith):

Replying to [comment:1 charettes]:


> Thanks for the example project. Could you also provide the full
traceback please.

{{{
Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/login/?next=/

Django Version: 1.8
Python Version: 3.4.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')


Traceback:
File "/Users/James/.virtualenvs/uuid-user/lib/python3.4/site-
packages/django/core/handlers/base.py" in get_response
222. response = middleware_method(request, response)
File "/Users/James/.virtualenvs/uuid-user/lib/python3.4/site-
packages/django/contrib/sessions/middleware.py" in process_response
49. request.session.save()
File "/Users/James/.virtualenvs/uuid-user/lib/python3.4/site-
packages/django/contrib/sessions/backends/db.py" in save
58.
session_data=self.encode(self._get_session(no_load=must_create)),
File "/Users/James/.virtualenvs/uuid-user/lib/python3.4/site-
packages/django/contrib/sessions/backends/base.py" in encode
89. serialized = self.serializer().dumps(session_dict)
File "/Users/James/.virtualenvs/uuid-user/lib/python3.4/site-
packages/django/core/signing.py" in dumps
90. return json.dumps(obj, separators=(',',
':')).encode('latin-1')
File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/__init__.py"
in dumps
237. **kw).encode(obj)
File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/encoder.py"
in encode
192. chunks = self.iterencode(o, _one_shot=True)
File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/encoder.py"
in iterencode
250. return _iterencode(o, 0)
File
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/json/encoder.py"
in default
173. raise TypeError(repr(o) + " is not JSON serializable")

Exception Type: TypeError at /login/
Exception Value: UUID('314cb5d6-593f-48f5-b1af-fadedde123d3') is not JSON
serializable
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:3>

Django

unread,
Jan 16, 2015, 4:33:54 PM1/16/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
----------------------------------+-------------------------------------

Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------------------
Changes (by charettes):

* has_patch: 0 => 1


Comment:

Create a [https://github.com/django/django/pull/3932 PR] but I'm not sure
`get_prep_value` is the correct solution here.

Maybe we should document that your session serializer should be able to
deal with your user primary key type?

I guess we could also rely on the check framework to make sure it's the
case.

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:4>

Django

unread,
Jan 16, 2015, 4:38:46 PM1/16/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
----------------------------------+-------------------------------------

Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------------------
Changes (by charettes):

* cc: charettes (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:5>

Django

unread,
Feb 11, 2015, 3:06:31 PM2/11/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
-------------------------------------+-------------------------------------

Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: new
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


Comment:

Tim's patch LGTM.

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:6>

Django

unread,
Feb 12, 2015, 7:39:13 AM2/12/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
-------------------------------------+-------------------------------------
Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: closed
Component: contrib.sessions | Version: 1.8alpha1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"0f7f5bc9e7a94ab91c2b3db29ef7cf000eff593f"]:
{{{
#!CommitTicketReference repository=""
revision="0f7f5bc9e7a94ab91c2b3db29ef7cf000eff593f"
Fixed #24161 -- Stored the user primary key as a serialized value in the
session.

This allows using a UUIDField primary key along with the JSON session
serializer.

Thanks to Trac alias jamesbeith for the report and Simon Charette
for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:7>

Django

unread,
Feb 12, 2015, 7:45:56 AM2/12/15
to django-...@googlegroups.com
#24161: Using UUIDField for id of custom User model prevents logging in
-------------------------------------+-------------------------------------
Reporter: jamesbeith | Owner: nobody
Type: Bug | Status: closed
Component: contrib.sessions | Version: 1.8alpha1

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"596564e808089f1263469dbf4744dcaa05b79222"]:
{{{
#!CommitTicketReference repository=""
revision="596564e808089f1263469dbf4744dcaa05b79222"
[1.8.x] Fixed #24161 -- Stored the user primary key as a serialized value
in the session.

This allows using a UUIDField primary key along with the JSON session
serializer.

Thanks to Trac alias jamesbeith for the report and Simon Charette
for the initial patch.

Backport of 0f7f5bc9e7a94ab91c2b3db29ef7cf000eff593f from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24161#comment:8>

Reply all
Reply to author
Forward
0 new messages