Closed ColeDCrawford closed 10 months ago
Same error:
raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type ModelName is not JSON serializable
I encountered the same problem with Python 3.11 and DAL 3.10.4rc
For now I had to downgrade to DAL 3.9.7 to fix the problem.
Here is a way to reproduce it, I hope it helps:
# models.py
from django.db import models
class Workspace(models.Model):
name = models.CharField(max_length=40)
# views.py
from dal import autocomplete
class WorkspaceAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
Workspace.objects.create(name="test to populate DB")
return Workspace.objects.all()
# urls.py
from django.urls import path
urlpatterns = [
path(
"workspace-autocomplete/",
WorkspaceAutocomplete.as_view(),
name="workspace-autocomplete",
),
]
// In a web browser, this GET request should return an error 500
GET http://localhost:8000/workspace-autocomplete/
This was just fixed in master 3f2880af19d1f6a37220b7ac9440f890ce0a4652 Will release in a moment
Please re-open if re-occuring with 3.11.0-rc1
I tested the 3.11.0-rc1 release in production this morning and the issue has been fixed ! Thanks :=)
I get errors like this across all my autocompletes after trying the latest RC
TypeError: Object of type Work is not JSON serializable "GET /_autocomplete/work/ HTTP/1.1" 500 138259