[Fixed]-TypeError at /en/ Object of type '__proxy__' is not JSON serializable


When using the JSONSerializer for storing data in the session object, that data must only contain values that can be translated to json.

In your code you are using some lazy objects, that’s where you get that __proxy__. Those have to be converted to strings before serializing.

new_value = {
        'url_name' : self.url_name,
        'verbose_name' : str(self.verbose_name),
        'url' : str(reverse_lazy(self.url_name, **kwargs))  # or just reverse()

You can also write your own serializer or use DjangoJSONEncoder (I’ve not tried that myself, but reading the docs, it seems that that serializer can handle lazy objects.)

Leave a comment