indeedeng/django-ptrack

handle uuid via json encoder

Opened this issue · 0 comments

It would be helpful if the default encoder used the DjangoJsonEncoder class for the JSON conversion to automatically handle types like uuid.

This is what happens when you pass a UUID pk through ptrack:

   File "/home/vagrant/.tox/py/lib/python3.7/site-packages/ptrack/templatetags/ptrack.py", line 20, in ptrack
     encoded_dict = {'ptrack_encoded_data': ptrack_encoder.encrypt(*args, **kwargs)}
   File "/home/vagrant/.tox/py/lib/python3.7/site-packages/ptrack/encoder.py", line 46, in encrypt
     data = json.dumps((args, kwargs))
   File "/usr/local/lib/python3.7/json/__init__.py", line 231, in dumps
     return _default_encoder.encode(obj)
   File "/usr/local/lib/python3.7/json/encoder.py", line 199, in encode
     chunks = self.iterencode(o, _one_shot=True)
   File "/usr/local/lib/python3.7/json/encoder.py", line 257, in iterencode
     return _iterencode(o, 0)
   File "/usr/local/lib/python3.7/json/encoder.py", line 179, in default
     raise TypeError(f'Object of type {o.__class__.__name__} '
 TypeError: Object of type UUID is not JSON serializable

It would be a small change to this line:

data = json.dumps((args, kwargs))