Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django.utils.datetime_safe module is removed in Django v5.0 #1902

Closed
2 tasks done
cclauss opened this issue Sep 25, 2023 · 8 comments
Closed
2 tasks done

django.utils.datetime_safe module is removed in Django v5.0 #1902

cclauss opened this issue Sep 25, 2023 · 8 comments
Assignees

Comments

@cclauss
Copy link
Contributor

cclauss commented Sep 25, 2023

When we run pytest on our project, we receive:

.venv/lib/python3.11/site-packages/haystack/fields.py:5
  /home/circleci/circleci-workdir/.venv/lib/python3.11/site-packages/haystack/fields.py:5:
  RemovedInDjango50Warning: The django.utils.datetime_safe module is deprecated.
    from django.utils import datetime_safe

https://github.com/search?q=repo%3Adjango-haystack%2Fdjango-haystack%20datetime_safe

  • haystack/fields.py
  • haystack/backends/whoosh_backend.py
  • test_haystack/whoosh_tests/test_whoosh_backend.py

As discussed but not implemented in #1828 @jayvdb

https://docs.djangoproject.com/en/5.0/releases/5.0
https://docs.djangoproject.com/en/5.0/releases/5.0/#features-removed-in-5-0

The undocumented django.utils.datetime_safe module is removed.

  • Tested with the latest Haystack release
  • Tested with the current Haystack master branch

Expected behavior

No pytest warnings.

Actual behavior

Pytest warnings.

Steps to reproduce the behavior

% pytest

Configuration

  • Operating system version:
  • Search engine version:
  • Python version: 3.11
  • Django version: 4.2.5
  • Haystack version: master
@benrxv
Copy link

benrxv commented Dec 5, 2023

Django 5.0 is now out, and this issue now officially is a problem

A link to proposed solution is documented above...

@cclauss
Copy link
Contributor Author

cclauss commented Dec 5, 2023

Agreed. This is blocking our upgrade to Django v5.0.

from django.utils import datetime_safe

https://docs.djangoproject.com/en/5.0/releases/5.0/#features-removed-in-5-0

@cclauss cclauss changed the title RemovedInDjango50Warning: The django.utils.datetime_safe module is deprecated django.utils.datetime_safe module is removed in Django v5.0 Dec 5, 2023
@benrxv
Copy link

benrxv commented Dec 5, 2023

Django now uses django.utils.formats.sanitize_strftime_format() to handle what datetime_safe was doing previously.
https://github.com/django/django/blob/0ee2b8c326d47387bacb713a3ab369fa9a7a22ee/django/utils/formats.py#L244

@cclauss
Copy link
Contributor Author

cclauss commented Dec 5, 2023

Are you able to create a PR for that?

@benrxv
Copy link

benrxv commented Dec 5, 2023

I'm not certain that haystack needs to sanitize the date strings. Django only seems to do this in a few very specific and important instances, and in one instance, django.utils.feedgenerator, they just replaced datetime_safe with python's native datetime.

@cclauss cclauss pinned this issue Dec 6, 2023
@cclauss
Copy link
Contributor Author

cclauss commented Dec 6, 2023

Fixed in #1915 but not yet released to PyPI. Workaround for Django v5.0 deployments:
% pip install git+https://github.com/django-haystack/django-haystack.git

@michaelmior
Copy link

@cclauss Thanks! Any ETA on a PyPI release?

@Albert-2024
Copy link

Fixed in #1915 but not yet released to PyPI. Workaround for Django v5.0 deployments: % pip install git+https://github.com/django-haystack/django-haystack.git

@cclauss thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants