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

Use of deprecated API of pydantic #113

Closed mthuurne closed 7 months ago

mthuurne commented 8 months ago

When I run the unit tests of an application that uses django-bootstrap-datepicker-plus, the following warning is logged:

.venv/lib/python3.10/site-packages/bootstrap_datepicker_plus/_config.py:24: PydanticDeprecatedSince20: The `json` method is deprecated; use `model_dump_json` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/
    return self.json(exclude_none=True)

In pyproject.toml of django-bootstrap-datepicker-plus, the Pydantic dependency is declared like this:

[tool.poetry.dependencies]
# ...
pydantic = "*"

This would mean that when Pydantic 3.0 is released, it will automatically get used by django-bootstrap-datepicker-plus and as a result, the code will break when it calls the removed json() method.

I think it would be safer to include a version range for the pydantic dependency, either accepting versions 1 and 2 (>=1.0,<3.0) or accepting only version 2.x (^2.0). In the latter case, the deprecation warning could be resolved by calling the method by its new model_dump_json() name instead.

I'm willing to submit a PR, but first I'd have to know which strategy you want to go for.

Versions used:

monim67 commented 7 months ago

The version constraint should be 1 & 2 untill we migrate to pedantic 2 and remove support for pedantic 1. PR's welcome.

christianwgd commented 1 month ago

Seems with django 5.1 pydantic 2.8.2 / pydantic_core 2.20.1 is installed, which leads to a warning message:

pydantic.warnings.PydanticDeprecatedSince20: Thejsonmethod is deprecated; usemodel_dump_jsoninstead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/ As soon as I change line 24 in _config.py from return self.json(exclude_none=True) to return self.model_dump_json(exclude_none=True) the warning has gone.

So I would suspect that we can safely make this change. Shall I send a PR? But maybe I don't have the whole picture...