| 1 |
======================== |
| 2 |
Submitting contributions |
| 3 |
======================== |
| 4 |
|
| 5 |
We're always grateful for contributions to Django's code. Indeed, bug reports |
| 6 |
with associated contributions will get fixed *far* more quickly than those |
| 7 |
without a solution. |
| 8 |
|
| 9 |
.. _trivial-change: |
| 10 |
|
| 11 |
Typo fixes and trivial documentation changes |
| 12 |
============================================ |
| 13 |
|
| 14 |
If you are fixing a really trivial issue, for example changing a word in the |
| 15 |
documentation, the preferred way to provide the patch is using GitHub pull |
| 16 |
requests without a Trac ticket. |
| 17 |
|
| 18 |
See the :doc:`working-with-git` for more details on how to use pull requests. |
| 19 |
|
| 20 |
"Claiming" tickets |
| 21 |
================== |
| 22 |
|
| 23 |
In an open-source project with hundreds of contributors around the world, it's |
| 24 |
important to manage communication efficiently so that work doesn't get |
| 25 |
duplicated and contributors can be as effective as possible. |
| 26 |
|
| 27 |
Hence, our policy is for contributors to "claim" tickets in order to let other |
| 28 |
developers know that a particular bug or feature is being worked on. |
| 29 |
|
| 30 |
If you have identified a contribution you want to make and you're capable of |
| 31 |
fixing it (as measured by your coding ability, knowledge of Django internals |
| 32 |
and time availability), claim it by following these steps: |
| 33 |
|
| 34 |
* `Login using your GitHub account`_ or `create an account`_ in our ticket |
| 35 |
system. If you have an account but have forgotten your password, you can |
| 36 |
reset it using the `password reset page`_. |
| 37 |
|
| 38 |
* If a ticket for this issue doesn't exist yet, create one in our |
| 39 |
`ticket tracker`_. Remember that proposals for new features should follow |
| 40 |
the :ref:`process for suggesting new features <requesting-features>`. |
| 41 |
|
| 42 |
* If a ticket for this issue already exists, make sure nobody else has |
| 43 |
claimed it. To do this, look at the "Owned by" section of the ticket. |
| 44 |
If it's assigned to "nobody," then it's available to be claimed. |
| 45 |
Otherwise, somebody else may be working on this ticket. Either find another |
| 46 |
bug/feature to work on, or contact the developer working on the ticket to |
| 47 |
offer your help. If a ticket has been assigned for weeks or months without |
| 48 |
any activity, it's probably safe to reassign it to yourself. |
| 49 |
|
| 50 |
* Log into your account, if you haven't already, by clicking "GitHub Login" |
| 51 |
or "DjangoProject Login" in the upper left of the ticket page. Once logged |
| 52 |
in, you can then click the "Modify Ticket" button near the bottom of the |
| 53 |
page. |
| 54 |
|
| 55 |
* Claim the ticket by clicking the "assign to" radio button in the "Action" |
| 56 |
section. Your username will be filled in the text box by default. |
| 57 |
|
| 58 |
* Finally click the "Submit changes" button at the bottom to save. |
| 59 |
|
| 60 |
.. note:: |
| 61 |
The Django software foundation requests that anyone contributing more than |
| 62 |
a :ref:`trivial change <trivial-change>`, to Django sign and submit a |
| 63 |
`Contributor License Agreement`_, this ensures that the Django Software |
| 64 |
Foundation has clear license to all contributions allowing for a clear |
| 65 |
license for all users. |
| 66 |
|
| 67 |
.. _Login using your GitHub account: https://code.djangoproject.com/github/login |
| 68 |
.. _Create an account: https://www.djangoproject.com/accounts/register/ |
| 69 |
.. _password reset page: https://www.djangoproject.com/accounts/password/reset/ |
| 70 |
.. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/ |
| 71 |
|
| 72 |
Ticket claimers' responsibility |
| 73 |
------------------------------- |
| 74 |
|
| 75 |
Once you've claimed a ticket, you have a responsibility to work on that ticket |
| 76 |
in a reasonably timely fashion. If you don't have time to work on it, either |
| 77 |
unclaim it or don't claim it in the first place! |
| 78 |
|
| 79 |
If there's no sign of progress on a particular claimed ticket for a week or |
| 80 |
two, another developer may ask you to relinquish the ticket claim so that it's |
| 81 |
no longer monopolized and somebody else can claim it. |
| 82 |
|
| 83 |
If you've claimed a ticket and it's taking a long time (days or weeks) to code, |
| 84 |
keep everybody updated by posting comments on the ticket. If you don't provide |
| 85 |
regular updates, and you don't respond to a request for a progress report, |
| 86 |
your claim on the ticket may be revoked. |
| 87 |
|
| 88 |
As always, more communication is better than less communication! |
| 89 |
|
| 90 |
Which tickets should be claimed? |
| 91 |
-------------------------------- |
| 92 |
|
| 93 |
Going through the steps of claiming tickets is overkill in some cases. |
| 94 |
|
| 95 |
In the case of small changes, such as typos in the documentation or small bugs |
| 96 |
that will only take a few minutes to fix, you don't need to jump through the |
| 97 |
hoops of claiming tickets. Submit your changes directly and you're done! |
| 98 |
|
| 99 |
It is *always* acceptable, regardless whether someone has claimed it or not, to |
| 100 |
link proposals to a ticket if you happen to have the changes ready. |
| 101 |
|
| 102 |
.. _patch-style: |
| 103 |
|
| 104 |
Contribution style |
| 105 |
================== |
| 106 |
|
| 107 |
Make sure that any contribution you do fulfills at least the following |
| 108 |
requirements: |
| 109 |
|
| 110 |
* The code required to fix a problem or add a feature is an essential part |
| 111 |
of a solution, but it is not the only part. A good fix should also include a |
| 112 |
:doc:`regression test <unit-tests>` to validate the behavior that has been |
| 113 |
fixed and to prevent the problem from arising again. Also, if some tickets |
| 114 |
are relevant to the code that you've written, mention the ticket numbers in |
| 115 |
some comments in the test so that one can easily trace back the relevant |
| 116 |
discussions after your patch gets committed, and the tickets get closed. |
| 117 |
|
| 118 |
* If the code adds a new feature, or modifies the behavior of an existing |
| 119 |
feature, the change should also contain documentation. |
| 120 |
|
| 121 |
When you think your work is ready to be reviewed, send :doc:`a GitHub pull |
| 122 |
request <working-with-git>`. |
| 123 |
If you can't send a pull request for some reason, you can also use patches in |
| 124 |
Trac. When using this style, follow these guidelines. |
| 125 |
|
| 126 |
* Submit patches in the format returned by the ``git diff`` command. |
| 127 |
|
| 128 |
* Attach patches to a ticket in the `ticket tracker`_, using the "attach |
| 129 |
file" button. Please *don't* put the patch in the ticket description |
| 130 |
or comment unless it's a single line patch. |
| 131 |
|
| 132 |
* Name the patch file with a ``.diff`` extension; this will let the ticket |
| 133 |
tracker apply correct syntax highlighting, which is quite helpful. |
| 134 |
|
| 135 |
Regardless of the way you submit your work, follow these steps. |
| 136 |
|
| 137 |
* Make sure your code fulfills the requirements in our :ref:`contribution |
| 138 |
checklist <patch-review-checklist>`. |
| 139 |
|
| 140 |
* Check the "Has patch" box on the ticket and make sure the "Needs |
| 141 |
documentation", "Needs tests", and "Patch needs improvement" boxes aren't |
| 142 |
checked. This makes the ticket appear in the "Patches needing review" queue |
| 143 |
on the `Development dashboard`_. |
| 144 |
|
| 145 |
.. _ticket tracker: https://code.djangoproject.com/ |
| 146 |
.. _Development dashboard: https://dashboard.djangoproject.com/ |
| 147 |
|
| 148 |
Contributions which require community feedback |
| 149 |
============================================== |
| 150 |
|
| 151 |
A wider community discussion is required when a patch introduces new Django |
| 152 |
functionality and makes some sort of design decision. This is especially |
| 153 |
important if the approach involves a :ref:`deprecation <deprecating-a-feature>` |
| 154 |
or introduces breaking changes. |
| 155 |
|
| 156 |
The following are different approaches for gaining feedback from the community. |
| 157 |
|
| 158 |
The new feature ideas tracker |
| 159 |
----------------------------- |
| 160 |
|
| 161 |
If you have an idea for a new feature, please create a new proposal (or join an |
| 162 |
existing discussion) following the :ref:`process for suggesting new features |
| 163 |
<requesting-features>`. You should explain the need for the change, go into |
| 164 |
details of the approach and discuss alternatives. |
| 165 |
|
| 166 |
The Django Forum |
| 167 |
---------------- |
| 168 |
|
| 169 |
You can propose a change (that is not a new feature idea) on the |
| 170 |
`Django Forum`_. You should explain the need for the change, go into details of |
| 171 |
the approach and discuss alternatives. |
| 172 |
|
| 173 |
Please include a link to such discussions in your contributions. |
| 174 |
|
| 175 |
Third party package |
| 176 |
------------------- |
| 177 |
|
| 178 |
Django does not accept experimental features. All features must follow our |
| 179 |
:ref:`deprecation policy <internal-release-deprecation-policy>`. Hence, it can |
| 180 |
take months or years for Django to iterate on an API design. |
| 181 |
|
| 182 |
If you need user feedback on a public interface, it is better to create a |
| 183 |
third-party package first. You can iterate on the public API much faster, while |
| 184 |
also validating the need for the feature. |
| 185 |
|
| 186 |
Once this package becomes stable and there are clear benefits of incorporating |
| 187 |
aspects into Django core, the next step is to propose its inclusion by |
| 188 |
following the :ref:`process for suggesting new features <requesting-features>`. |
| 189 |
|
| 190 |
Django Enhancement Proposal (DEP) |
| 191 |
--------------------------------- |
| 192 |
|
| 193 |
Similar to Python’s PEPs, Django has `Django Enhancement Proposals`_ or DEPs. A |
| 194 |
DEP is a design document which provides information to the Django community, or |
| 195 |
describes a new feature or process for Django. They provide concise technical |
| 196 |
specifications of features, along with rationales. DEPs are also the primary |
| 197 |
mechanism for proposing and collecting community input on major new features. |
| 198 |
|
| 199 |
Before considering writing a DEP, it is recommended to first open a discussion |
| 200 |
following the :ref:`process for suggesting new features <requesting-features>`. |
| 201 |
This allows the community to provide feedback and helps refine the proposal. |
| 202 |
Once the DEP is ready the :ref:`Steering Council <steering-council>` votes on |
| 203 |
whether to accept it. |
| 204 |
|
| 205 |
Some examples of DEPs that have been approved and fully implemented: |
| 206 |
|
| 207 |
* `DEP 181: ORM Expressions <https://github.com/django/deps/blob/main/final/0181-orm-expressions.rst>`_ |
| 208 |
* `DEP 182: Multiple Template Engines <https://github.com/django/deps/blob/main/final/0182-multiple-template-engines.rst>`_ |
| 209 |
* `DEP 201: Simplified routing syntax <https://github.com/django/deps/blob/main/final/0201-simplified-routing-syntax.rst>`_ |
| 210 |
|
| 211 |
.. _Django Forum: https://forum.djangoproject.com/ |
| 212 |
.. _Django Enhancement Proposals: https://github.com/django/deps |
| 213 |
|
| 214 |
.. _deprecating-a-feature: |
| 215 |
|
| 216 |
Deprecating a feature |
| 217 |
===================== |
| 218 |
|
| 219 |
There are a couple of reasons that code in Django might be deprecated: |
| 220 |
|
| 221 |
* If a feature has been improved or modified in a backwards-incompatible way, |
| 222 |
the old feature or behavior will be deprecated. |
| 223 |
|
| 224 |
* Sometimes Django will include a backport of a Python library that's not |
| 225 |
included in a version of Python that Django currently supports. When Django |
| 226 |
no longer needs to support the older version of Python that doesn't include |
| 227 |
the library, the library will be deprecated in Django. |
| 228 |
|
| 229 |
As the :ref:`deprecation policy<internal-release-deprecation-policy>` describes, |
| 230 |
the first release of Django that deprecates a feature (``A.B``) should raise a |
| 231 |
``RemovedInDjangoXXWarning`` (where XX is the Django version where the feature |
| 232 |
will be removed) when the deprecated feature is invoked. Assuming we have good |
| 233 |
test coverage, these warnings are converted to errors when :ref:`running the |
| 234 |
test suite <running-unit-tests>` with warnings enabled: |
| 235 |
``python -Wa runtests.py``. Thus, when adding a ``RemovedInDjangoXXWarning`` |
| 236 |
you need to eliminate or silence any warnings generated when running the tests. |
| 237 |
|
| 238 |
The first step is to remove any use of the deprecated behavior by Django itself. |
| 239 |
Next you can silence warnings in tests that actually test the deprecated |
| 240 |
behavior by using the ``ignore_warnings`` decorator, either at the test or class |
| 241 |
level: |
| 242 |
|
| 243 |
#) In a particular test:: |
| 244 |
|
| 245 |
from django.test import ignore_warnings |
| 246 |
from django.utils.deprecation import RemovedInDjangoXXWarning |
| 247 |
|
| 248 |
|
| 249 |
@ignore_warnings(category=RemovedInDjangoXXWarning) |
| 250 |
def test_foo(self): ... |
| 251 |
|
| 252 |
#) For an entire test case:: |
| 253 |
|
| 254 |
from django.test import ignore_warnings |
| 255 |
from django.utils.deprecation import RemovedInDjangoXXWarning |
| 256 |
|
| 257 |
|
| 258 |
@ignore_warnings(category=RemovedInDjangoXXWarning) |
| 259 |
class MyDeprecatedTests(unittest.TestCase): ... |
| 260 |
|
| 261 |
You should also add a test for the deprecation warning:: |
| 262 |
|
| 263 |
from django.utils.deprecation import RemovedInDjangoXXWarning |
| 264 |
|
| 265 |
|
| 266 |
def test_foo_deprecation_warning(self): |
| 267 |
msg = "Expected deprecation message" |
| 268 |
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg) as ctx: |
| 269 |
# invoke deprecated behavior |
| 270 |
... |
| 271 |
self.assertEqual(ctx.filename, __file__) |
| 272 |
|
| 273 |
It's important to include a ``RemovedInDjangoXXWarning`` comment above code |
| 274 |
which has no warning reference, but will need to be changed or removed when the |
| 275 |
deprecation ends. This could include hooks which have been added to keep the |
| 276 |
previous behavior, or standalone items that are unnecessary or unused when the |
| 277 |
deprecation ends. For example:: |
| 278 |
|
| 279 |
import warnings |
| 280 |
from django.utils.deprecation import RemovedInDjangoXXWarning |
| 281 |
|
| 282 |
|
| 283 |
# RemovedInDjangoXXWarning. |
| 284 |
def old_private_helper(): |
| 285 |
# Helper function that is only used in foo(). |
| 286 |
pass |
| 287 |
|
| 288 |
|
| 289 |
def foo(): |
| 290 |
warnings.warn( |
| 291 |
"foo() is deprecated.", |
| 292 |
category=RemovedInDjangoXXWarning, |
| 293 |
stacklevel=2, |
| 294 |
) |
| 295 |
old_private_helper() |
| 296 |
... |
| 297 |
|
| 298 |
Finally, there are a couple of updates to Django's documentation to make: |
| 299 |
|
| 300 |
#) If the existing feature is documented, mark it deprecated in documentation |
| 301 |
using the ``.. deprecated:: A.B`` annotation. Include a short description |
| 302 |
and a note about the upgrade path if applicable. |
| 303 |
|
| 304 |
#) Add a description of the deprecated behavior, and the upgrade path if |
| 305 |
applicable, to the current release notes (``docs/releases/A.B.txt``) under |
| 306 |
the "Features deprecated in A.B" heading. |
| 307 |
|
| 308 |
#) Add an entry in the deprecation timeline (``docs/internals/deprecation.txt``) |
| 309 |
under the appropriate version describing what code will be removed. |
| 310 |
|
| 311 |
Once you have completed these steps, you are finished with the deprecation. |
| 312 |
In each :term:`feature release <Feature release>`, all |
| 313 |
``RemovedInDjangoXXWarning``\s matching the new version are removed. |
| 314 |
|
| 315 |
Testing with a Django project |
| 316 |
============================= |
| 317 |
|
| 318 |
It's important to test local changes using a Django project. This allows |
| 319 |
ensuring that the changes behave as expected in a real environment, especially |
| 320 |
for user-facing features such as templates, forms, or the admin. |
| 321 |
|
| 322 |
To do this: |
| 323 |
|
| 324 |
#. Create a virtual environment and :ref:`install the cloned copy of Django in |
| 325 |
editable mode <intro-contributing-install-local-copy>`. |
| 326 |
|
| 327 |
#. Set up a Django project outside the source tree (you can use the :doc:`first |
| 328 |
part of the tutorial </intro/tutorial01>` for guidance). |
| 329 |
|
| 330 |
With this setup, any changes made to the Django checkout will take effect |
| 331 |
immediately in the test project, allowing manual testing of contributions |
| 332 |
against a new or existing app. |
| 333 |
|
| 334 |
JavaScript contributions |
| 335 |
======================== |
| 336 |
|
| 337 |
For information on JavaScript contributions, see the :ref:`javascript-patches` |
| 338 |
documentation. |
| 339 |
|
| 340 |
Optimization patches |
| 341 |
==================== |
| 342 |
|
| 343 |
Patches aiming to deliver a performance improvement should provide benchmarks |
| 344 |
showing the before and after impact of the patch and sharing the commands for |
| 345 |
reviewers to reproduce. |
| 346 |
|
| 347 |
.. _django-asv-benchmarks: |
| 348 |
|
| 349 |
``django-asv`` benchmarks |
| 350 |
------------------------- |
| 351 |
|
| 352 |
`django-asv`_ monitors the performance of Django code over time. These |
| 353 |
benchmarks can be run on a pull request by labeling the pull request with |
| 354 |
``benchmark``. Adding to these benchmarks is highly encouraged. |
| 355 |
|
| 356 |
.. _django-asv: https://github.com/django/django-asv/ |
| 357 |
|
| 358 |
.. _patch-review-checklist: |
| 359 |
|
| 360 |
Contribution checklist |
| 361 |
====================== |
| 362 |
|
| 363 |
Use this checklist to review a pull request. If this contribution would not be |
| 364 |
:ref:`considered trivial <trivial-change>`, first ensure it has an accepted |
| 365 |
ticket before proceeding with the review. |
| 366 |
|
| 367 |
If the pull request passes all the criteria below and is not your own, please |
| 368 |
set the "Triage Stage" on the corresponding Trac ticket to "Ready for checkin". |
| 369 |
If you've left comments for improvement on the pull request, please tick the |
| 370 |
appropriate flags on the Trac ticket based on the results of your review: |
| 371 |
"Patch needs improvement", "Needs documentation", and/or "Needs tests". As time |
| 372 |
and interest permits, mergers do final reviews of "Ready for checkin" tickets |
| 373 |
and will either commit the changes or bump it back to "Accepted" if further |
| 374 |
work needs to be done. |
| 375 |
|
| 376 |
If you're looking to become a member of the `triage & review team |
| 377 |
<https://www.djangoproject.com/foundation/teams/#triage-review-team>`_, doing |
| 378 |
thorough reviews of contributions is a great way to earn trust. |
| 379 |
|
| 380 |
Looking for a patch to review? Check out the "Patches needing review" section |
| 381 |
of the `Django Development Dashboard <https://dashboard.djangoproject.com/>`_. |
| 382 |
|
| 383 |
Looking to get your pull request reviewed? Ensure the Trac flags on the ticket |
| 384 |
are set so that the ticket appears in that queue. |
| 385 |
|
| 386 |
Documentation |
| 387 |
------------- |
| 388 |
|
| 389 |
* Does the documentation build without any errors (``make html``, or |
| 390 |
``make.bat html`` on Windows, from the ``docs`` directory)? |
| 391 |
* Does the documentation follow the writing style guidelines in |
| 392 |
:doc:`/internals/contributing/writing-documentation`? |
| 393 |
* Are there any :ref:`spelling errors <documentation-spelling-check>`? |
| 394 |
|
| 395 |
Bugs |
| 396 |
---- |
| 397 |
|
| 398 |
* Is there a proper regression test (the test should fail before the fix |
| 399 |
is applied)? |
| 400 |
* If it's a bug that :ref:`qualifies for a backport <supported-versions-policy>` |
| 401 |
to the stable version of Django, is there a release note in |
| 402 |
``docs/releases/A.B.C.txt``? Bug fixes that will be applied only to the main |
| 403 |
branch don't need a release note. |
| 404 |
|
| 405 |
New Features |
| 406 |
------------ |
| 407 |
|
| 408 |
* Are there tests to "exercise" all of the new code? |
| 409 |
* Is there a release note in ``docs/releases/A.B.txt``? |
| 410 |
* Is there documentation for the feature and is it :ref:`annotated |
| 411 |
appropriately <documenting-new-features>` with |
| 412 |
``.. versionadded:: A.B`` or ``.. versionchanged:: A.B``? |
| 413 |
|
| 414 |
Deprecating a feature |
| 415 |
--------------------- |
| 416 |
|
| 417 |
See the :ref:`deprecating-a-feature` guide. |
| 418 |
|
| 419 |
All code changes |
| 420 |
---------------- |
| 421 |
|
| 422 |
* Does the :doc:`coding style |
| 423 |
</internals/contributing/writing-code/coding-style>` conform to our |
| 424 |
guidelines? Are there any ``black``, ``blacken-docs``, ``flake8``, |
| 425 |
``isort``, or ``zizmor`` errors? You can install the :ref:`pre-commit |
| 426 |
<coding-style-pre-commit>` hooks to automatically catch these errors. |
| 427 |
* If the change is backwards incompatible in any way, is there a note |
| 428 |
in the release notes (``docs/releases/A.B.txt``)? |
| 429 |
* Is Django's test suite passing? |
| 430 |
* If the change affects the Django admin or rendered HTML output, has |
| 431 |
:ref:`accessibility testing <accessibility-testing-baseline>` been done? |
| 432 |
|
| 433 |
All tickets |
| 434 |
----------- |
| 435 |
|
| 436 |
* Is the pull request a single squashed commit with a message that follows our |
| 437 |
:ref:`commit message format <committing-guidelines>`? |
| 438 |
* Are you the patch author and a new contributor? Please add yourself to the |
| 439 |
:source:`AUTHORS` file and submit a `Contributor License Agreement`_. |
| 440 |
* Does this have an accepted ticket on Trac? All contributions require a ticket |
| 441 |
unless the :ref:`change is considered trivial <trivial-change>`. |
| 442 |
|
| 443 |
.. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/ |