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

WidgetMixin __init__ breaks when attrs is None #1334

Open oberix opened 1 year ago

oberix commented 1 year ago

Hello, I found this unexpected behavior when using ListSelect2 in a MultiWidget. Basically __init__ breaks if attrs is None.

Django MultiWidget has the following signature

def __init__(self, widgets, attrs=None):
    ...

But in dal.widgets.WidgetMixin.__init__ happens this

def __init__(self, url=None, forward=None, *args, **kwargs):
     ...
     self.placeholder = kwargs.get("attrs", {}).get("data-placeholder")
     ...

In other words WidgetMixin assume attrs is either a dict or is not in kwargs, but in the base class Widgets it defaults to None.

Not a big dial, it can be easily worked around, but I think that it should be allowed to blindly pass attrs to all subwidget of a MultiWidget (that's what works with a plain Select at last).

Regards

jpic commented 10 months ago

Agreed, None should be supported