-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object of type Theme is not JSON serializable #356
Comments
This is strange, I also use redis_cache and don’t have this problem. |
I can work on setting up a minimal repro 👍 |
@merwok - The most minimal repro I've been able to come up with is the following in a django shell after installing this package: $ theme = Theme.objects.get()
$ theme
<Theme: Django>
$ from json import JSONEncoder
$ chunks = JSONEncoder().iterencode(theme, _one_shot=True)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
----> 1 chunks = JSONEncoder().iterencode(theme, _one_shot=True)
~/.asdf/installs/python/3.10.11/lib/python3.10/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
~/.asdf/installs/python/3.10.11/lib/python3.10/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
TypeError: Object of type Theme is not JSON serializable I can work on making a smaller project to replicate but that may take some time. |
@TheBitShepherd Does this happen also on a fresh new installation without other third-party requirements installed? |
@fabiocaccamo - If I install this package in a fresh install without third-party dependencies everything works as expected. The issue is definitely with I was able to get things working by specifying a local memory cache for the
|
And the This is very strange... |
That’s only showing the surface cause! We already knew from the original traceback that this particular call is a problem. The thing I wanted to see is: why does the combination of django-redis and django-admin-interface causes the call to happen 🙂 → a repro of minimal django project (dependencies and settings) |
In my project, django-redis 5.3.0 uses a pickle serializer by default. |
My project is using
I'm seeing the same behavior even when I update it to |
Alright then! Can you configure a different cache for this package? See https://github.com/fabiocaccamo/django-admin-interface/blob/main/admin_interface/cache.py#L6 |
@merwok - Yes. As I mentioned above configuring a different cache for this package was one way I found to alleviate the error. 👍 |
@TheBitShepherd could you try to manually get the default theme instance and serialize it using the django-redis JSONEncoder? |
@fabiocaccamo - It gives the same stacktrace, so not sure that's much additional help. The
|
So the issue can be reproduced easily using I'm pretty sure the same error would be raised with any other model. |
I think the options here are:
|
@merwok considering that this is not a bug of this library I would opt for improving the caching documentation. |
@fabiocaccamo @merwok - If you'd like I'd be happy to open an MR to enhance the caching documentation with what we found here. |
@TheBitShepherd that would be great, thanks! |
@TheBitShepherd thanks! |
Python version
3.10.11
Django version
4.0.10
Package version
0.28.3
Current behavior (bug description)
On startup the project encounters an error
Desired behavior
Project should start without error
Hi there! I'm really interested in using this package for my team's project, but on startup I'm receiving the following stacktrace. It looks like it may not be playing nicely with some of the dependency packages our project has, as this package doesn't encounter this error when I install it on a fresh project.
Has this issue been encountered by anyone before? Is there a known remedy? Thanks in advance!
Upvote & Fund
The text was updated successfully, but these errors were encountered: