Skip to content

CRUDHistoryAdminMixin does not support Django 4 #322

@hydrospanner

Description

@hydrospanner
  1. What version of Python and Django are you using?

Python: 3.12.3
Django: 4.2.11

  1. What operating system and processor architecture are you using?
    Ubuntu 24.04.1 LTS
    x86_64

  2. What did you do?
    Import the CRUDHistoryAdminMixin to use in a ModelAdmin class.

from easyaudit.crudhistory_admin_mixin import CRUDHistoryAdminMixin
  1. What did you expect to see?
    An import without errors.

  2. What did you see instead?

Importing the Mixin is raising an ImportError because it uses ugettext_lazy which was removed in Django 4.0, replaced with gettext_lazy.

To replicate the issue in this project, if the above import is added to tests/test_main.py, pytest will output:

_____________________ ERROR collecting tests/test_main.py ______________________
ImportError while importing test module '/home/jt/code/django-easy-audit/tests/test_main.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_main.py:13: in <module>
    from easyaudit.crudhistory_admin_mixin import CRUDHistoryAdminMixin
easyaudit/crudhistory_admin_mixin.py:11: in <module>
    from django.utils.translation import ugettext_lazy as _
E   ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (/home/jt/code/django-easy-audit/.venv/lib/python3.12/site-packages/django/utils/translation/__init__.py)

The fix is as simple as updating the function name in this line to gettext_lazy.

For reference, this PR added the feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions