yourlabs / django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v4 alpha, v3 stable, v2 & v1 deprecated.
https://django-autocomplete-light.readthedocs.io
MIT License
1.81k stars 468 forks source link

DAL 3.10.4rc breaks autocomplete views #1341

Closed ColeDCrawford closed 10 months ago

ColeDCrawford commented 1 year ago

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

bubublik commented 1 year ago

Same error: raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type ModelName is not JSON serializable

ducdetronquito commented 11 months ago

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/
jpic commented 10 months ago

This was just fixed in master 3f2880af19d1f6a37220b7ac9440f890ce0a4652 Will release in a moment

jpic commented 10 months ago

Please re-open if re-occuring with 3.11.0-rc1

ducdetronquito commented 10 months ago

I tested the 3.11.0-rc1 release in production this morning and the issue has been fixed ! Thanks :=)