Wagtail: Use of uggettext functions is deprecated

Created on 18 Feb 2020  ·  5Comments  ·  Source: wagtail/wagtail

Issue Summary

Calling any of ugettext(), ugettext_lazy(), ugettext_noop(), ungettext() and ungettext_lazy() functions from django.utils.translation will raise a RemovedInDjango40Warning deprecation warning.

Steps to Reproduce

  1. Start the development server with warnings enabled for a Wagtail project with Django 3.0 installed: python -Wall manage.py runserver
  2. Observe the output. It will output dozens of warnings similar to this one:
/Users/stormh/torchbox/wagtail/wagtail/admin/edit_handlers.py:762: RemovedInDjango40Warning: django.utils.translation.ugettext_lazy() is deprecated in favor of django.utils.translation.gettext_lazy().
  'heading': ugettext_lazy('Scheduled publishing'),
  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes

ugettext functions have been deprecated in Django 3.0

The reason for the deprecation is that these are legacy aliases for their corresponding gettext counterparts. They were once used for unicode compatibility with Python 2.7 according to this ticket

How do we solve this?

We should replace all references to ugettext functions with their gettext counterparts. This should have no negative influence because Wagtail does not support Python 2.7 anymore and this change would be compatible with Django 2.2 LTS.

Now, do we have to hurry implementing this change? No, not really. The ugettext functions are scheduled to be removed in Django 4.0. Which is scheduled to be released in 2022 according to this chart I took from https://www.djangoproject.com/download/

It would however be nice to get rid of those nasty deprecation warnings for that my-project-is-fully-up-to-date experience 👌

Technical details

  • Python version: 3.8.1
  • Django version: 3.0.3
  • Wagtail version: 2.9a0
  • Browser version: n/a
Django i18n good first issue Bug

Most helpful comment

@danihodovic Depends on your use case, this is how you hide them when running pytest.

[pytest]
filterwarnings =
    ignore::django.utils.deprecation.RemovedInDjango40Warning

All 5 comments

Is there any way to silence this warning until it's resolved?

@danihodovic Depends on your use case, this is how you hide them when running pytest.

[pytest]
filterwarnings =
    ignore::django.utils.deprecation.RemovedInDjango40Warning

Thank you @marteinn !

Completed in #5907, but since it's entirely possible that new occurrences may sneak in as a result of merging existing PRs, I'll leave this open to remind us to do another sweep before the 2.9 release.

Re-checked, and no new occurrences have crept in, so I think we're all good 👍

Was this page helpful?
0 / 5 - 0 ratings