Skip to content

chore: upgrade Django 4.2 → 5.2 - #9325

Merged
sriramveeraghanta merged 2 commits into
previewfrom
chore/django-5.2-upgrade
Jul 29, 2026
Merged

chore: upgrade Django 4.2 → 5.2#9325
sriramveeraghanta merged 2 commits into
previewfrom
chore/django-5.2-upgrade

Conversation

@sriramveeraghanta

@sriramveeraghanta sriramveeraghanta commented Jun 26, 2026

Copy link
Copy Markdown
Member

Description

Upgrades the API backend (apps/api, the only Django service in the monorepo) from Django 4.2.30 LTS to 5.2.15 LTS, with all Django-coupled dependencies bumped to versions that officially support 5.2.

An end-to-end audit (12 breaking-change scans + settings audit + 129-migration scan + per-dependency compatibility checks) found the application code already 5.2-clean, so this is primarily a coordinated dependency bump plus the few touch-points the upgrade required. No runtime/infra blockers: Python 3.12 (≥3.10 ✓), Postgres 15.7 (≥14 ✓), psycopg 3 ✓.

Dependency bumps (requirements/):

  • Django 4.2.30 → 5.2.15; DRF 3.15.2 → 3.17.1; channels 4.1.0 → 4.3.2; django-cors-headers 4.3.1 → 4.9.0; django-filter 24.2 → 25.2; django-storages 1.14.2 → 1.14.6; django-redis 5.4.0 → 7.0.0; celery 5.4.0 → 5.5.3; django-celery-beat 2.6.0 → 2.9.0; django-celery-results 2.5.1 → 2.6.0; drf-spectacular 0.28.0 → 0.29.0; scout-apm 3.1.0 → 3.5.3; psycopg (+binary/+c) 3.3.0 → 3.3.4; whitenoise 6.11.0 → 6.12.0; django-debug-toolbar 4.3.0 → 6.0.0 (dev); pytest-django 4.5.2 → 4.12.0 (test).
  • OpenTelemetry set, django-crum, and pytz intentionally held (already 5.2-compatible; bumping adds churn with no 5.2 benefit). debug-toolbar pinned to 6.0 (not 7.0, which drops Django 4.2) and celery to 5.5.3 (not 5.6.x, which reverted the SQS transport change).

Code changes the upgrade required:

  • plane/urls.py — gate the debug-toolbar URL include on apps.is_installed("debug_toolbar"). django-debug-toolbar 6.0 ships a real model (HistoryEntry) that raises during manage.py check when the app isn't in INSTALLED_APPS (test settings use DEBUG=True but don't install it).
  • plane/db/migrations/0122_… — a state-only AlterField for three ManyToManyFields (issue.assignees, draftissue.assignees, module.members) that use through_fields (Django 5.1 normalized M2M deconstruction). sqlmigrate confirms it is a no-op — zero database impact; required only so makemigrations --check stays green.
  • plane/tests/contract/app/test_authentication.py — add a module-level autouse cache.clear() fixture. This fixes 8 pre-existing test failures that are unrelated to the upgrade (verified identical on the Django 4.2 preview baseline): the per-IP AuthenticationThrottle stores history in the shared cache and the magic sign-in/up test classes didn't reset it between tests.

A full migration plan / audit write-up is included at apps/api/docs/django-5.2-migration-plan.md.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

Verified in the containerized harness (docker-compose-test.yml: python:3.12.5-alpine, Postgres 15.7, Valkey, RabbitMQ, MinIO) on Django 5.2.15:

  • pip install -r requirements/test.txt — resolves, no conflicts.
  • manage.py check — "System check identified no issues".
  • manage.py makemigrations --check --dry-run — no changes.
  • manage.py migrate — full history (db 00010122 + django_celery_beat + license + sessions) applies cleanly on Postgres 15.
  • pytest (full suite) — 393 passed, 0 failed.
  • ENABLE_DRF_SPECTACULAR=1 manage.py spectacular — schema generates under drf-spectacular 0.29.

Recommended pre-merge smoke (not yet run): boot the api / worker / beat / migrator entrypoints against a local stack and exercise an auth flow, a file upload (S3/MinIO), and a Celery task + scheduled beat task.

References


🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added a comprehensive Django 4.2 → 5.2 migration plan with checklist, acceptance criteria, risk/mitigation, and rollback guidance.
  • Bug Fixes

    • Improved authentication test reliability by clearing cached authentication throttle state between tests.
    • Ensured the debug toolbar routes only load when the debug toolbar component is installed.
  • Chores

    • Updated dependency pins across core, local, and test environments (including DRF Spectacular, debug toolbar, and pytest-django).
    • Added a database migration to keep user-to-item assignment many-to-many relationships aligned.

Upgrade Django 4.2.30 LTS → 5.2.15 LTS and bump all Django-coupled
dependencies to versions that officially support 5.2 (DRF 3.17.1,
channels 4.3.2, django-cors-headers 4.9.0, django-filter 25.2,
django-storages 1.14.6, django-redis 7.0.0, celery 5.5.3,
django-celery-beat 2.9.0, django-celery-results 2.6.0,
drf-spectacular 0.29.0, scout-apm 3.5.3, psycopg 3.3.4,
whitenoise 6.12.0, django-debug-toolbar 6.0.0, pytest-django 4.12.0).
OpenTelemetry set, django-crum and pytz held (already 5.2-compatible).

Code changes the upgrade required:
- urls.py: gate the debug-toolbar URL include on apps.is_installed(),
  since django-debug-toolbar 6.0 ships a model that errors when the app
  isn't in INSTALLED_APPS (test settings run DEBUG=True but don't install it).
- migration 0122: state-only AlterField for three M2M fields using
  through_fields (Django 5.1 deconstruction normalization); sqlmigrate is a
  no-op, zero DB impact.
- test_authentication.py: module-level autouse cache.clear() fixture to fix
  8 pre-existing throttle test-isolation failures (identical on the 4.2
  baseline) so the suite is green.

Verified on python:3.12-alpine + Postgres 15.7: check clean,
makemigrations --check clean, full migrate applies, pytest 393 passed.

Adds the migration plan/audit write-up under apps/api/docs/.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 59c9540b-146d-4b00-b218-cedd47fad295

📥 Commits

Reviewing files that changed from the base of the PR and between 8c5b7fb and b8faea3.

📒 Files selected for processing (1)
  • apps/api/plane/tests/contract/app/test_authentication.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/plane/tests/contract/app/test_authentication.py

📝 Walkthrough

Walkthrough

Adds a Django 4.2→5.2 migration plan, updates API dependencies, guards debug toolbar URL wiring, isolates authentication throttle tests, and adds a migration normalizing three many-to-many relationships.

Changes

Django 5.2 migration

Layer / File(s) Summary
Migration plan
apps/api/docs/django-5.2-migration-plan.md
Documents migration scope, verification evidence, execution steps, acceptance criteria, rollback, risks, and follow-ups.
Compatibility updates and test isolation
apps/api/requirements/base.txt, apps/api/requirements/local.txt, apps/api/requirements/test.txt, apps/api/plane/urls.py, apps/api/plane/tests/contract/app/test_authentication.py
Updates dependency pins, checks debug_toolbar installation before registering routes, and clears authentication throttle cache keys around contract tests.
M2M migration
apps/api/plane/db/migrations/0122_alter_draftissue_assignees_alter_issue_assignees_and_more.py
Alters DraftIssue.assignees, Issue.assignees, and Module.members with explicit through models and through_fields mappings.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: pablohashescobar, copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: upgrading Django from 4.2 to 5.2.
Description check ✅ Passed The description covers all required template sections with a clear summary, change type, tests, and references.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/django-5.2-upgrade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/plane/tests/contract/app/test_authentication.py`:
- Around line 23-36: The module-wide auth cache fixture is wiping the entire
shared Redis cache, which can affect unrelated state across tests. Update the
`_reset_auth_throttle_cache` fixture in `test_authentication.py` to remove only
`AuthenticationThrottle` entries, using targeted deletion of
`throttle_authentication_*` keys (for example via a helper like
`_clear_auth_throttle_keys`) instead of calling `cache.clear()`. Keep the
cleanup before and after the test via the fixture, but scope it to the throttle
cache keys only.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0bac99d-03e4-42a5-a225-07cff70464fe

📥 Commits

Reviewing files that changed from the base of the PR and between 90ae845 and 8c5b7fb.

📒 Files selected for processing (7)
  • apps/api/docs/django-5.2-migration-plan.md
  • apps/api/plane/db/migrations/0122_alter_draftissue_assignees_alter_issue_assignees_and_more.py
  • apps/api/plane/tests/contract/app/test_authentication.py
  • apps/api/plane/urls.py
  • apps/api/requirements/base.txt
  • apps/api/requirements/local.txt
  • apps/api/requirements/test.txt

Comment thread apps/api/plane/tests/contract/app/test_authentication.py Outdated
The module-wide _reset_auth_throttle_cache fixture called cache.clear(),
wiping the entire shared Redis cache between tests. Replace it with
targeted deletion of throttle_authentication_* keys (DRF
SimpleRateThrottle history for AuthenticationThrottle) via
cache.delete_pattern, keeping the same before/after cleanup.
Copilot AI review requested due to automatic review settings July 29, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sriramveeraghanta
sriramveeraghanta merged commit ca3b48e into preview Jul 29, 2026
15 checks passed
@sriramveeraghanta
sriramveeraghanta deleted the chore/django-5.2-upgrade branch July 29, 2026 14:28
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.

3 participants