Submitting patches¶
Weâre always grateful for patches to Djangoâs code. Indeed, bug reports with associated patches will get fixed far more quickly than those without patches.
Typo fixes and trivial documentation changes¶
If you are fixing a really trivial issue, for example changing a word in the documentation, the preferred way to provide the patch is using GitHub pull requests without a Trac ticket.
See the Working with Git and GitHub for more details on how to use pull requests.
âClaimingâ tickets¶
In an open-source project with hundreds of contributors around the world, itâs important to manage communication efficiently so that work doesnât get duplicated and contributors can be as effective as possible.
Hence, our policy is for contributors to âclaimâ tickets in order to let other developers know that a particular bug or feature is being worked on.
If you have identified a contribution you want to make and youâre capable of fixing it (as measured by your coding ability, knowledge of Django internals and time availability), claim it by following these steps:
Login using your GitHub account or create an account in our ticket system. If you have an account but have forgotten your password, you can reset it using the password reset page.
If a ticket for this issue doesnât exist yet, create one in our ticket tracker.
If a ticket for this issue already exists, make sure nobody else has claimed it. To do this, look at the âOwned byâ section of the ticket. If itâs assigned to ânobody,â then itâs available to be claimed. Otherwise, somebody else may be working on this ticket. Either find another bug/feature to work on, or contact the developer working on the ticket to offer your help. If a ticket has been assigned for weeks or months without any activity, itâs probably safe to reassign it to yourself.
Log into your account, if you havenât already, by clicking âGitHub Loginâ or âDjangoProject Loginâ in the upper left of the ticket page.
Claim the ticket by clicking the âassign to myselfâ radio button under âActionâ near the bottom of the page, then click âSubmit changes.â
Note
The Django software foundation requests that anyone contributing more than a trivial patch to Django sign and submit a Contributor License Agreement, this ensures that the Django Software Foundation has clear license to all contributions allowing for a clear license for all users.
Ticket claimersâ responsibility¶
Once youâve claimed a ticket, you have a responsibility to work on that ticket in a reasonably timely fashion. If you donât have time to work on it, either unclaim it or donât claim it in the first place!
If thereâs no sign of progress on a particular claimed ticket for a week or two, another developer may ask you to relinquish the ticket claim so that itâs no longer monopolized and somebody else can claim it.
If youâve claimed a ticket and itâs taking a long time (days or weeks) to code, keep everybody updated by posting comments on the ticket. If you donât provide regular updates, and you donât respond to a request for a progress report, your claim on the ticket may be revoked.
As always, more communication is better than less communication!
Which tickets should be claimed?¶
Going through the steps of claiming tickets is overkill in some cases.
In the case of small changes, such as typos in the documentation or small bugs that will only take a few minutes to fix, you donât need to jump through the hoops of claiming tickets. Submit your patch directly and youâre done!
It is always acceptable, regardless whether someone has claimed it or not, to submit patches to a ticket if you happen to have a patch ready.
Patch style¶
Make sure that any contribution you do fulfills at least the following requirements:
The code required to fix a problem or add a feature is an essential part of a patch, but it is not the only part. A good patch should also include a regression test to validate the behavior that has been fixed and to prevent the problem from arising again. Also, if some tickets are relevant to the code that youâve written, mention the ticket numbers in some comments in the test so that one can easily trace back the relevant discussions after your patch gets committed, and the tickets get closed.
If the code associated with a patch adds a new feature, or modifies behavior of an existing feature, the patch should also contain documentation.
When you think your work is ready to be reviewed, send a GitHub pull request. Please review the patch yourself using our patch review checklist first.
If you canât send a pull request for some reason, you can also use patches in Trac. When using this style, follow these guidelines.
Submit patches in the format returned by the
git diffcommand.Attach patches to a ticket in the ticket tracker, using the âattach fileâ button. Please donât put the patch in the ticket description or comment unless itâs a single line patch.
Name the patch file with a
.diffextension; this will let the ticket tracker apply correct syntax highlighting, which is quite helpful.
Regardless of the way you submit your work, follow these steps.
Make sure your code fulfills the requirements in our patch review checklist.
Check the âHas patchâ box on the ticket and make sure the âNeeds documentationâ, âNeeds testsâ, and âPatch needs improvementâ boxes arenât checked. This makes the ticket appear in the âPatches needing reviewâ queue on the Development dashboard.
Non-trivial patches¶
A ânon-trivialâ patch is one that is more than a small bug fix. Itâs a patch that introduces Django functionality and makes some sort of design decision.
If you provide a non-trivial patch, include evidence that alternatives have been discussed on the Django Forum or django-developers list.
If youâre not sure whether your patch should be considered non-trivial, ask on the ticket for opinions.
Deprecating a feature¶
There are a couple of reasons that code in Django might be deprecated:
If a feature has been improved or modified in a backwards-incompatible way, the old feature or behavior will be deprecated.
Sometimes Django will include a backport of a Python library thatâs not included in a version of Python that Django currently supports. When Django no longer needs to support the older version of Python that doesnât include the library, the library will be deprecated in Django.
As the deprecation policy describes,
the first release of Django that deprecates a feature (A.B) should raise a
RemovedInDjangoXXWarning (where XX is the Django version where the feature
will be removed) when the deprecated feature is invoked. Assuming we have good
test coverage, these warnings are converted to errors when running the
test suite with warnings enabled:
python -Wa runtests.py. Thus, when adding a RemovedInDjangoXXWarning
you need to eliminate or silence any warnings generated when running the tests.
The first step is to remove any use of the deprecated behavior by Django itself.
Next you can silence warnings in tests that actually test the deprecated
behavior by using the ignore_warnings decorator, either at the test or class
level:
In a particular test:
from django.test import ignore_warnings from django.utils.deprecation import RemovedInDjangoXXWarning @ignore_warnings(category=RemovedInDjangoXXWarning) def test_foo(self): ...
For an entire test case:
from django.test import ignore_warnings from django.utils.deprecation import RemovedInDjangoXXWarning @ignore_warnings(category=RemovedInDjangoXXWarning) class MyDeprecatedTests(unittest.TestCase): ...
You should also add a test for the deprecation warning:
from django.utils.deprecation import RemovedInDjangoXXWarning
def test_foo_deprecation_warning(self):
msg = "Expected deprecation message"
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
# invoke deprecated behavior
...
Itâs important to include a RemovedInDjangoXXWarning comment above code
which has no warning reference, but will need to be changed or removed when the
deprecation ends. This could include hooks which have been added to keep the
previous behavior, or standalone items that are unnecessary or unused when the
deprecation ends. For example:
import warnings
from django.utils.deprecation import RemovedInDjangoXXWarning
# RemovedInDjangoXXWarning.
def old_private_helper():
# Helper function that is only used in foo().
pass
def foo():
warnings.warn(
"foo() is deprecated.",
category=RemovedInDjangoXXWarning,
)
old_private_helper()
...
Finally, there are a couple of updates to Djangoâs documentation to make:
If the existing feature is documented, mark it deprecated in documentation using the
.. deprecated:: A.Bannotation. Include a short description and a note about the upgrade path if applicable.Add a description of the deprecated behavior, and the upgrade path if applicable, to the current release notes (
docs/releases/A.B.txt) under the âFeatures deprecated in A.Bâ heading.Add an entry in the deprecation timeline (
docs/internals/deprecation.txt) under the appropriate version describing what code will be removed.
Once you have completed these steps, you are finished with the deprecation.
In each feature release, all
RemovedInDjangoXXWarnings matching the new version are removed.
JavaScript patches¶
For information on JavaScript patches, see the JavaScript patches documentation.
Patch review checklist¶
Use this checklist to review a pull request. If you are reviewing a pull request that is not your own and it passes all the criteria below, please set the âTriage Stageâ on the corresponding Trac ticket to âReady for checkinâ. If youâve left comments for improvement on the pull request, please tick the appropriate flags on the Trac ticket based on the results of your review: âPatch needs improvementâ, âNeeds documentationâ, and/or âNeeds testsâ. As time and interest permits, mergers do final reviews of âReady for checkinâ tickets and will either commit the patch or bump it back to âAcceptedâ if further works need to be done. If youâre looking to become a merger, doing thorough reviews of patches is a great way to earn trust.
Looking for a patch to review? Check out the âPatches needing reviewâ section of the Django Development Dashboard. Looking to get your patch reviewed? Ensure the Trac flags on the ticket are set so that the ticket appears in that queue.
Documentation¶
Does the documentation build without any errors (
make html, ormake.bat htmlon Windows, from thedocsdirectory)?Does the documentation follow the writing style guidelines in Writing documentation?
Are there any spelling errors?
Bugs¶
Is there a proper regression test (the test should fail before the fix is applied)?
If itâs a bug that qualifies for a backport to the stable version of Django, is there a release note in
docs/releases/A.B.C.txt? Bug fixes that will be applied only to the main branch donât need a release note.
New Features¶
Are there tests to âexerciseâ all of the new code?
Is there a release note in
docs/releases/A.B.txt?Is there documentation for the feature and is it annotated appropriately with
.. versionadded:: A.Bor.. versionchanged:: A.B?
Deprecating a feature¶
See the Deprecating a feature guide.
All code changes¶
Does the coding style conform to our guidelines? Are there any
black,blacken-docs,flake8,isort, orzizmorerrors? You can install the pre-commit hooks to automatically catch these errors.If the change is backwards incompatible in any way, is there a note in the release notes (
docs/releases/A.B.txt)?Is Djangoâs test suite passing?
All tickets¶
Is the pull request a single squashed commit with a message that follows our commit message format?
Are you the patch author and a new contributor? Please add yourself to the AUTHORS file and submit a Contributor License Agreement.