Skip to content

Add django-upgrade to pre-commit hooks - #9683

Merged
browniebroke merged 8 commits into
encode:mainfrom
ulgens:django-upgrade-precommit
Jul 27, 2026
Merged

Add django-upgrade to pre-commit hooks#9683
browniebroke merged 8 commits into
encode:mainfrom
ulgens:django-upgrade-precommit

Conversation

@ulgens

@ulgens ulgens commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

Description

Similar to #9682, adding django-upgrade to help maintenance efforts.

@ulgens
ulgens marked this pull request as draft April 9, 2025 07:20
@ulgens
ulgens force-pushed the django-upgrade-precommit branch 2 times, most recently from 0b86ae9 to 5ce273b Compare April 9, 2025 07:53
@auvipy
auvipy self-requested a review April 29, 2025 07:27
@stale

stale Bot commented Jul 19, 2025

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Jul 19, 2025
@stale stale Bot closed this Oct 18, 2025
@browniebroke browniebroke reopened this Oct 20, 2025
@ulgens
ulgens force-pushed the django-upgrade-precommit branch from 5ce273b to 5792933 Compare December 1, 2025 02:28
@browniebroke
browniebroke marked this pull request as ready for review July 25, 2026 19:05

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.

Pull request overview

This PR adds django-upgrade to the repo’s pre-commit configuration and includes a set of automated refactors aligned with modern Django APIs (notably request.headers and headers=... in the test client/request factory), plus a few URLpattern cleanups.

Changes:

  • Add django-upgrade as a pre-commit hook.
  • Switch various header reads/writes from request.META[...] / HTTP_* kwargs to request.headers[...] / headers={...}.
  • Replace a couple of re_path() URL patterns with equivalent path() patterns using path converters.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
.pre-commit-config.yaml Adds django-upgrade to pre-commit hooks.
rest_framework/authentication.py Reads Authorization via request.headers in get_authorization_header().
rest_framework/negotiation.py Reads Accept header via request.headers for content negotiation.
rest_framework/throttling.py Reads X-Forwarded-For via request.headers for client identification.
rest_framework/authtoken/admin.py Registers TokenProxy admin via @admin.register.
tests/test_decorators.py Updates Accept header assertion to use request.headers.
tests/test_middleware.py Uses headers={...} when sending Authorization in tests.
tests/test_relations.py Converts a re_path() URL to path() with <path:name>.
tests/test_renderers.py Uses headers={...} instead of HTTP_ACCEPT in client requests.
tests/test_requests_client.py Uses request.headers to check Content-Type.
tests/test_response.py Uses headers={...} instead of HTTP_ACCEPT in client requests.
tests/test_testing.py Switches to request.headers for Authorization and Content-Type test assertions.
tests/test_throttling.py Rebuilds requests with headers={...} to vary XFF reliably.
tests/test_urlpatterns.py Updates URL pattern examples used by format_suffix_patterns tests.
tests/test_versioning.py Converts an unversioned route from re_path() to path() with <path:foo>.
Comments suppressed due to low confidence (2)

tests/test_urlpatterns.py:148

  • This regex was tightened from [0-9]+ to exactly two digits ([0-9]{2}), which reduces the generality of the test URL pattern without providing any benefit for the behavior under test (format suffix resolution). Consider reverting to the original [0-9]+ to keep the pattern representative.
            re_path(r'^re_path/(?P<child>[0-9]{2})$', dummy_view)

tests/test_urlpatterns.py:151

  • Similarly, constraining the parent capture group to exactly two digits ([0-9]{2}) is an unnecessary semantic change in a test that is focused on URL resolving/format suffix behavior. Revert to [0-9]+ to keep the pattern generic and easier to reason about.
            re_path(r'^pre_path/(?P<parent>[0-9]{2})/', include(nested_patterns), {'foo': 'bar'}),

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_urlpatterns.py
Comment thread tests/test_urlpatterns.py
Comment thread .pre-commit-config.yaml
@browniebroke
browniebroke merged commit 8c4bfc7 into encode:main Jul 27, 2026
7 checks passed
@ulgens
ulgens deleted the django-upgrade-precommit branch July 28, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants