monim67 / django-bootstrap-datepicker-plus

Bootstrap3/Bootstrap4/Bootstrap5 DatePickerInput, TimePickerInput, DateTimePickerInput, MonthPickerInput, YearPickerInput with date-range-picker functionality for django >= 2.0
https://pypi.python.org/pypi/django-bootstrap-datepicker-plus
MIT License
223 stars 61 forks source link

UserWarning: Pydantic serializer warnings: Expected `Union[bool, int, str, dict[str, str]]` but got `list` - serialized value may not be as expected #117

Open ptrba opened 5 months ago

ptrba commented 5 months ago

To Reproduce Using options https://getdatepicker.com/4/Options/#daysofweekdisabled for example:

picker = DatePickerInput(options={'daysOfWeekDisabled': [0,6]})
picker.config.to_attr_value()

will show:

UserWarning: Pydantic serializer warnings:
  Expected `Union[bool, int, str, dict[str, str]]` but got `list` - serialized value may not be as expected 

This warning does not have any consequences. The picker is rendered correctly.

As far as I can judge, this is due to schemas.py:9

WidgetOptions: TypeAlias = Dict[str, Union[bool, int, str, Dict[str, str]]]

where Union does not include list. Thus a fix:

WidgetOptions: TypeAlias = Dict[str, Union[bool, int, str, Dict[str, str],list[int]]]

should do the job. I did not go through all options of https://getdatepicker.com/4/Options/. There might be more of these typing issues. A less restrictive schema might be more appropriate here:

WidgetOptions: TypeAlias = Dict[str, typing.Any]

Expected behavior

There should be no warning.

Setup Information (please complete the following information):