UUID is not JSON Serializable

4,351 views
Skip to first unread message

Sergei G

unread,
Jun 4, 2014, 5:39:24 PM6/4/14
to mezzani...@googlegroups.com
I am trying to get cartridge-payments to work.

Exception Type: TypeError at /shop/checkout/
Exception Value: UUID('ab07bbb9-78ff-45dd-a670-251bb3c65163') is not JSON serializable

Django: 1.6.5
Python: 2.7.6

Traceback:
File "lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  199.                 response = middleware_method(request, response)
File "lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
  38.                     request.session.save()
File "lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
  57.             session_data=self.encode(self._get_session(no_load=must_create)),
File "lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in encode
  87.         serialized = self.serializer().dumps(session_dict)
File "lib/python2.7/site-packages/django/core/signing.py" in dumps
  88.         return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/usr/local/lib/python2.7/json/__init__.py" in dumps
  250.         sort_keys=sort_keys, **kw).encode(obj)
File "/usr/local/lib/python2.7/json/encoder.py" in encode
  207.         chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/lib/python2.7/json/encoder.py" in iterencode
  270.         return _iterencode(o, 0)
File "/usr/local/lib/python2.7/json/encoder.py" in default
  184.         raise TypeError(repr(o) + " is not JSON serializable")

Exception Type: TypeError at /shop/checkout/
Exception Value: UUID('ab07bbb9-78ff-45dd-a670-251bb3c65163') is not JSON serializable

Sergei G

unread,
Jun 4, 2014, 7:26:43 PM6/4/14
to mezzani...@googlegroups.com
After some research my conclusion is that UUID object serialization is not supported by default json encoder/decoder. I think the solution would be to implement UUID serialization for session and set new serializer with settings.SESSION_SERIALER...  UUID.urn form looks most reasonable for uuid detection during decoding.

I just realized that cartridge-payments targets multiple payment models and I don't need that. Thus I think can ignore the issue for now and look for direct paypal integration instead.

Stephen McDonald

unread,
Jun 4, 2014, 8:07:15 PM6/4/14
to mezzani...@googlegroups.com
Rather than ignoring it why don't you send a pull request with a fix - you could just convert the UUID to/from a string before it goes in and out of the session, it's probably a two line change :-)



--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen McDonald
http://jupo.org
Reply all
Reply to author
Forward
0 new messages