Add django-upgrade to pre-commit hooks - #9683
Merged
Merged
Conversation
ulgens
marked this pull request as draft
April 9, 2025 07:20
ulgens
force-pushed
the
django-upgrade-precommit
branch
2 times, most recently
from
April 9, 2025 07:53
0b86ae9 to
5ce273b
Compare
auvipy
self-requested a review
April 29, 2025 07:27
|
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. |
ulgens
force-pushed
the
django-upgrade-precommit
branch
from
December 1, 2025 02:28
5ce273b to
5792933
Compare
browniebroke
marked this pull request as ready for review
July 25, 2026 19:05
browniebroke
approved these changes
Jul 25, 2026
Contributor
There was a problem hiding this comment.
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-upgradeas apre-commithook. - Switch various header reads/writes from
request.META[...]/HTTP_*kwargs torequest.headers[...]/headers={...}. - Replace a couple of
re_path()URL patterns with equivalentpath()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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Similar to #9682, adding django-upgrade to help maintenance efforts.