Skip to content

Upgrade django-admin-tools to Django 4.0–4.2 compatibility with deprecation cleanup and expanded CI matrix - #4

Merged
willgearty merged 8 commits into
espfrom
copilot/upgrade-django-to-4-x
May 13, 2026
Merged

willgearty merged 8 commits into
espfrom
copilot/upgrade-django-to-4-x

Conversation

Copilot AI commented May 13, 2026 •

Copy link
Copy Markdown

This updates the project to an explicit Django 4.x target (4.0, 4.1, 4.2), removes legacy compatibility code that is unreachable on the new support matrix, and expands GitHub Actions coverage across supported Python/Django combinations.

  • Admin site resolution scope narrowed

    • Removed the previously introduced get_admin_site() fallback/runtime resolution behavior.
    • Restored direct esp.admin usage for this PR scope.
  • Python 3.12 compatibility fix

    • Replaced import imp usage in admin_tools/dashboard/registry.py with importlib.util.find_spec.
  • Deprecated compatibility shim cleanup

    • Removed Python 2 / pre-Django-4 fallback branches, including:
      • django.core.urlresolvers fallbacks
      • ugettext_lazy fallbacks
      • force_text fallbacks
      • django.utils.importlib fallbacks
      • if django.VERSION < (2, 0), < (2, 2), < (3, 2) branches
      • default_app_config in admin_tools/__init__.py
      • Python 2 __unicode__ shim in admin_tools/menu/models.py
      • Python 2 urllib.unquote fallback in admin_tools/menu/forms.py
      • old csrf_exempt fallback imports in dashboard/menu views
  • Obsolete files removed

    • Deleted:
      • admin_tools/dashboard/south_migrations/
      • admin_tools/menu/south_migrations/
      • .travis.yml
  • Documentation updates

    • Updated INSTALL to reflect Python 3.8+ and Django 4.0–4.2 support.
    • Added an Unreleased section to CHANGELOG summarizing these changes.
  • Django 4.x support matrix

    • tox.ini validates against:
      • Django>=4.0,<4.1
      • Django>=4.1,<4.2
      • Django>=4.2,<4.3
  • GitHub Actions test workflow

    • .github/workflows/tests.yml runs tests on pull requests and pushes to master and esp.
    • Expanded matrix to full supported combinations:
      • Django 4.0: Python 3.8–3.10
      • Django 4.1: Python 3.8–3.11
      • Django 4.2: Python 3.8–3.12
    • Explicit workflow permissions: contents: read
    • Test command: python -W all test_proj/manage.py test

Copilot AI linked an issue May 13, 2026 that may be closed by this pull request
6 tasks
Copilot AI changed the title [WIP] Upgrade Django to version 4.x Upgrade django-admin-tools to Django 4.0–4.2 compatibility May 13, 2026
Copilot AI requested a review from willgearty May 13, 2026 19:46
@willgearty
willgearty marked this pull request as ready for review May 13, 2026 19:57
@willgearty

Copy link
Copy Markdown
Member

@copilot add a GitHub Action workflow to run the tests.

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Author

@copilot add a GitHub Action workflow to run the tests.

Implemented in commit afa9650. I added .github/workflows/tests.yml to run the test suite on pull requests and pushes (master/esp) with a Django 4.0/4.1/4.2 matrix, plus explicit read-only workflow permissions.

Copilot AI changed the title Upgrade django-admin-tools to Django 4.0–4.2 compatibility Upgrade django-admin-tools to Django 4.0–4.2 compatibility and add CI test workflow May 13, 2026
@willgearty

Copy link
Copy Markdown
Member

@copilot Let's narrow this PR's scope. Please drop the get_admin_site runtime change entirely — the current_app / all_sites logic is dead code on a real request, the except ImportError would mask bugs in esp/admin.py, and on the esp branch esp.admin is always present anyway, so the fallback isn't exercised in production. I'd rather keep this PR to metadata + CI + deprecation cleanup and handle admin-site resolution separately if it comes up.

With that out, please make the following changes here:

  1. Fix the Python 3.12 break: admin_tools/dashboard/registry.py uses import imp (removed in Py 3.12, which is in your new matrix). Replace with importlib.util.find_spec.

  2. Address "deprecated features" from issue Upgrade Django to 4.x #3 — remove the compatibility shims that target Python 2 or Django <4.0, since none of those branches are reachable on the new support matrix:

    • from django.core.urlresolvers import reverse try/except blocks across the codebase
    • from django.utils.translation import ugettext_lazy as _ fallbacks
    • from django.utils.encoding import force_text as force_str fallbacks
    • from django.utils.importlib import import_module fallbacks
    • All if django.VERSION < (2, 0) / < (2, 2) / < (3, 2) blocks
    • Drop default_app_config from admin_tools/__init__.py (removed in Django 4.1)
    • __unicode__ / sys.version_info[0] == 2 shim in admin_tools/menu/models.py
    • from urllib import unquote Py2 fallback in admin_tools/menu/forms.py
    • csrf_exempt Django <1.x fallback in both views.py files
  3. Delete obsolete files: admin_tools/dashboard/south_migrations/, admin_tools/menu/south_migrations/, .travis.yml.

  4. Update INSTALL — still references Python 2.7 and Django 1.11.

  5. Add a CHANGELOG entry.

  6. Expand the CI matrix to test each Django version against all its supported Python versions (4.0: py3.8–3.10; 4.1: py3.8–3.11; 4.2: py3.8–3.12). Please confirm the suite passes on all cells before re-requesting review.

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Author

@copilot Let's narrow this PR's scope. Please drop the get_admin_site runtime change entirely — the current_app / all_sites logic is dead code on a real request, the except ImportError would...

Implemented in commits 30afc7a, a7853b3, and 6d8f82d.

I removed the get_admin_site fallback/runtime resolution logic and reverted the related fallback test, replaced imp with importlib.util.find_spec, removed the requested Python 2 / pre-Django-4 shims, deleted admin_tools/dashboard/south_migrations/, admin_tools/menu/south_migrations/, and .travis.yml, updated INSTALL, added a CHANGELOG entry, and expanded .github/workflows/tests.yml to the full Django/Python matrix (4.0: py3.8-3.10, 4.1: py3.8-3.11, 4.2: py3.8-3.12).

Local suite passes (python -W all test_proj/manage.py test). The GitHub Actions matrix run for the latest commit is currently action_required (run 25831719265), so all cells are configured but awaiting workflow approval/execution in GitHub.

No UI changes in this PR.

Copilot AI changed the title Upgrade django-admin-tools to Django 4.0–4.2 compatibility and add CI test workflow Upgrade django-admin-tools to Django 4.0–4.2 compatibility with deprecation cleanup and expanded CI matrix May 13, 2026
@willgearty

Copy link
Copy Markdown
Member

@copilot

  1. Add a comment at the top of test_proj/esp/admin.py explaining why the stub exists, so the next reader doesn't have to trace it. Something like:

    # Stub so that admin_tools.utils.get_admin_site() can resolve
    # `from esp.admin import admin_site` in the test project without
    # the real ESP package installed.
  2. In admin_tools/dashboard/registry.py, narrow the except (AttributeError, ImportError, ValueError) around util.find_spec(...) to except (ImportError, ValueError) — find_spec doesn't raise AttributeError.

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Author

@copilot

  1. Add a comment at the top of test_proj/esp/admin.py explaining why the stub exists, so the next reader doesn't have to trace it. Something like:
    ...

Done in 6e9d60b.

I added the explanatory stub comment at the top of test_proj/esp/admin.py and narrowed util.find_spec(...) handling in admin_tools/dashboard/registry.py to except (ImportError, ValueError).

No UI changes in this update, so no screenshot applies.

@willgearty
willgearty merged commit 94966a5 into esp May 13, 2026
12 checks passed
@willgearty
willgearty deleted the copilot/upgrade-django-to-4-x branch May 13, 2026 23:24
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

Successfully merging this pull request may close these issues.

Upgrade Django to 4.x

2 participants