submitting-patches.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. ==================
  2. Submitting patches
  3. ==================
  4. We're always grateful for patches to Django's code. Indeed, bug reports
  5. with associated patches will get fixed *far* more quickly than those
  6. without patches.
  7. Typo fixes and trivial documentation changes
  8. ============================================
  9. If you are fixing a really trivial issue, for example changing a word in the
  10. documentation, the preferred way to provide the patch is using GitHub pull
  11. requests without a Trac ticket.
  12. See the :doc:`working-with-git` for more details on how to use pull requests.
  13. "Claiming" tickets
  14. ==================
  15. In an open-source project with hundreds of contributors around the world, it's
  16. important to manage communication efficiently so that work doesn't get
  17. duplicated and contributors can be as effective as possible.
  18. Hence, our policy is for contributors to "claim" tickets in order to let other
  19. developers know that a particular bug or feature is being worked on.
  20. If you have identified a contribution you want to make and you're capable of
  21. fixing it (as measured by your coding ability, knowledge of Django internals
  22. and time availability), claim it by following these steps:
  23. * `Login using your GitHub account`_ or `create an account`_ in our ticket
  24. system. If you have an account but have forgotten your password, you can
  25. reset it using the `password reset page`_.
  26. * If a ticket for this issue doesn't exist yet, create one in our
  27. `ticket tracker`_.
  28. * If a ticket for this issue already exists, make sure nobody else has
  29. claimed it. To do this, look at the "Owned by" section of the ticket.
  30. If it's assigned to "nobody," then it's available to be claimed.
  31. Otherwise, somebody else may be working on this ticket. Either find another
  32. bug/feature to work on, or contact the developer working on the ticket to
  33. offer your help. If a ticket has been assigned for weeks or months without
  34. any activity, it's probably safe to reassign it to yourself.
  35. * Log into your account, if you haven't already, by clicking "GitHub Login"
  36. or "DjangoProject Login" in the upper left of the ticket page.
  37. * Claim the ticket by clicking the "assign to myself" radio button under
  38. "Action" near the bottom of the page, then click "Submit changes."
  39. .. note::
  40. The Django software foundation requests that anyone contributing more than
  41. a trivial patch to Django sign and submit a `Contributor License
  42. Agreement`_, this ensures that the Django Software Foundation has clear
  43. license to all contributions allowing for a clear license for all users.
  44. .. _Login using your GitHub account: https://code.djangoproject.com/github/login
  45. .. _Create an account: https://www.djangoproject.com/accounts/register/
  46. .. _password reset page: https://www.djangoproject.com/accounts/password/reset/
  47. .. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/
  48. Ticket claimers' responsibility
  49. -------------------------------
  50. Once you've claimed a ticket, you have a responsibility to work on that ticket
  51. in a reasonably timely fashion. If you don't have time to work on it, either
  52. unclaim it or don't claim it in the first place!
  53. If there's no sign of progress on a particular claimed ticket for a week or
  54. two, another developer may ask you to relinquish the ticket claim so that it's
  55. no longer monopolized and somebody else can claim it.
  56. If you've claimed a ticket and it's taking a long time (days or weeks) to code,
  57. keep everybody updated by posting comments on the ticket. If you don't provide
  58. regular updates, and you don't respond to a request for a progress report,
  59. your claim on the ticket may be revoked.
  60. As always, more communication is better than less communication!
  61. Which tickets should be claimed?
  62. --------------------------------
  63. Going through the steps of claiming tickets is overkill in some cases.
  64. In the case of small changes, such as typos in the documentation or small bugs
  65. that will only take a few minutes to fix, you don't need to jump through the
  66. hoops of claiming tickets. Submit your patch directly and you're done!
  67. It is *always* acceptable, regardless whether someone has claimed it or not, to
  68. submit patches to a ticket if you happen to have a patch ready.
  69. .. _patch-style:
  70. Patch style
  71. ===========
  72. Make sure that any contribution you do fulfills at least the following
  73. requirements:
  74. * The code required to fix a problem or add a feature is an essential part
  75. of a patch, but it is not the only part. A good patch should also include a
  76. :doc:`regression test <unit-tests>` to validate the behavior that has been
  77. fixed and to prevent the problem from arising again. Also, if some tickets
  78. are relevant to the code that you've written, mention the ticket numbers in
  79. some comments in the test so that one can easily trace back the relevant
  80. discussions after your patch gets committed, and the tickets get closed.
  81. * If the code associated with a patch adds a new feature, or modifies
  82. behavior of an existing feature, the patch should also contain
  83. documentation.
  84. When you think your work is ready to be reviewed, send :doc:`a GitHub pull
  85. request <working-with-git>`. Please review the patch yourself using our
  86. :ref:`patch review checklist <patch-review-checklist>` first.
  87. If you can't send a pull request for some reason, you can also use patches in
  88. Trac. When using this style, follow these guidelines.
  89. * Submit patches in the format returned by the ``git diff`` command.
  90. * Attach patches to a ticket in the `ticket tracker`_, using the "attach
  91. file" button. Please *don't* put the patch in the ticket description
  92. or comment unless it's a single line patch.
  93. * Name the patch file with a ``.diff`` extension; this will let the ticket
  94. tracker apply correct syntax highlighting, which is quite helpful.
  95. Regardless of the way you submit your work, follow these steps.
  96. * Make sure your code fulfills the requirements in our :ref:`patch review
  97. checklist <patch-review-checklist>`.
  98. * Check the "Has patch" box on the ticket and make sure the "Needs
  99. documentation", "Needs tests", and "Patch needs improvement" boxes aren't
  100. checked. This makes the ticket appear in the "Patches needing review" queue
  101. on the `Development dashboard`_.
  102. .. _ticket tracker: https://code.djangoproject.com/
  103. .. _Development dashboard: https://dashboard.djangoproject.com/
  104. Non-trivial patches
  105. ===================
  106. A "non-trivial" patch is one that is more than a small bug fix. It's a patch
  107. that introduces Django functionality and makes some sort of design decision.
  108. If you provide a non-trivial patch, include evidence that alternatives have
  109. been discussed on the `Django Forum`_ or |django-developers| list.
  110. If you're not sure whether your patch should be considered non-trivial, ask on
  111. the ticket for opinions.
  112. .. _Django Forum: https://forum.djangoproject.com/
  113. .. _deprecating-a-feature:
  114. Deprecating a feature
  115. =====================
  116. There are a couple of reasons that code in Django might be deprecated:
  117. * If a feature has been improved or modified in a backwards-incompatible way,
  118. the old feature or behavior will be deprecated.
  119. * Sometimes Django will include a backport of a Python library that's not
  120. included in a version of Python that Django currently supports. When Django
  121. no longer needs to support the older version of Python that doesn't include
  122. the library, the library will be deprecated in Django.
  123. As the :ref:`deprecation policy<internal-release-deprecation-policy>` describes,
  124. the first release of Django that deprecates a feature (``A.B``) should raise a
  125. ``RemovedInDjangoXXWarning`` (where XX is the Django version where the feature
  126. will be removed) when the deprecated feature is invoked. Assuming we have good
  127. test coverage, these warnings are converted to errors when :ref:`running the
  128. test suite <running-unit-tests>` with warnings enabled:
  129. ``python -Wa runtests.py``. Thus, when adding a ``RemovedInDjangoXXWarning``
  130. you need to eliminate or silence any warnings generated when running the tests.
  131. The first step is to remove any use of the deprecated behavior by Django itself.
  132. Next you can silence warnings in tests that actually test the deprecated
  133. behavior by using the ``ignore_warnings`` decorator, either at the test or class
  134. level:
  135. #) In a particular test::
  136. from django.test import ignore_warnings
  137. from django.utils.deprecation import RemovedInDjangoXXWarning
  138. @ignore_warnings(category=RemovedInDjangoXXWarning)
  139. def test_foo(self): ...
  140. #) For an entire test case::
  141. from django.test import ignore_warnings
  142. from django.utils.deprecation import RemovedInDjangoXXWarning
  143. @ignore_warnings(category=RemovedInDjangoXXWarning)
  144. class MyDeprecatedTests(unittest.TestCase): ...
  145. You should also add a test for the deprecation warning::
  146. from django.utils.deprecation import RemovedInDjangoXXWarning
  147. def test_foo_deprecation_warning(self):
  148. msg = "Expected deprecation message"
  149. with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
  150. # invoke deprecated behavior
  151. ...
  152. It's important to include a ``RemovedInDjangoXXWarning`` comment above code
  153. which has no warning reference, but will need to be changed or removed when the
  154. deprecation ends. This could include hooks which have been added to keep the
  155. previous behavior, or standalone items that are unnecessary or unused when the
  156. deprecation ends. For example::
  157. import warnings
  158. from django.utils.deprecation import RemovedInDjangoXXWarning
  159. # RemovedInDjangoXXWarning.
  160. def old_private_helper():
  161. # Helper function that is only used in foo().
  162. pass
  163. def foo():
  164. warnings.warn(
  165. "foo() is deprecated.",
  166. category=RemovedInDjangoXXWarning,
  167. )
  168. old_private_helper()
  169. ...
  170. Finally, there are a couple of updates to Django's documentation to make:
  171. #) If the existing feature is documented, mark it deprecated in documentation
  172. using the ``.. deprecated:: A.B`` annotation. Include a short description
  173. and a note about the upgrade path if applicable.
  174. #) Add a description of the deprecated behavior, and the upgrade path if
  175. applicable, to the current release notes (``docs/releases/A.B.txt``) under
  176. the "Features deprecated in A.B" heading.
  177. #) Add an entry in the deprecation timeline (``docs/internals/deprecation.txt``)
  178. under the appropriate version describing what code will be removed.
  179. Once you have completed these steps, you are finished with the deprecation.
  180. In each :term:`feature release <Feature release>`, all
  181. ``RemovedInDjangoXXWarning``\s matching the new version are removed.
  182. JavaScript patches
  183. ==================
  184. For information on JavaScript patches, see the :ref:`javascript-patches`
  185. documentation.
  186. .. _patch-review-checklist:
  187. Patch review checklist
  188. ======================
  189. Use this checklist to review a pull request. If you are reviewing a pull
  190. request that is not your own and it passes all the criteria below, please set
  191. the "Triage Stage" on the corresponding Trac ticket to "Ready for checkin".
  192. If you've left comments for improvement on the pull request, please tick the
  193. appropriate flags on the Trac ticket based on the results of your review:
  194. "Patch needs improvement", "Needs documentation", and/or "Needs tests". As time
  195. and interest permits, mergers do final reviews of "Ready for checkin" tickets
  196. and will either commit the patch or bump it back to "Accepted" if further works
  197. need to be done. If you're looking to become a merger, doing thorough reviews
  198. of patches is a great way to earn trust.
  199. Looking for a patch to review? Check out the "Patches needing review" section
  200. of the `Django Development Dashboard <https://dashboard.djangoproject.com/>`_.
  201. Looking to get your patch reviewed? Ensure the Trac flags on the ticket are
  202. set so that the ticket appears in that queue.
  203. Documentation
  204. -------------
  205. * Does the documentation build without any errors (``make html``, or
  206. ``make.bat html`` on Windows, from the ``docs`` directory)?
  207. * Does the documentation follow the writing style guidelines in
  208. :doc:`/internals/contributing/writing-documentation`?
  209. * Are there any :ref:`spelling errors <documentation-spelling-check>`?
  210. Bugs
  211. ----
  212. * Is there a proper regression test (the test should fail before the fix
  213. is applied)?
  214. * If it's a bug that :ref:`qualifies for a backport <supported-versions-policy>`
  215. to the stable version of Django, is there a release note in
  216. ``docs/releases/A.B.C.txt``? Bug fixes that will be applied only to the main
  217. branch don't need a release note.
  218. New Features
  219. ------------
  220. * Are there tests to "exercise" all of the new code?
  221. * Is there a release note in ``docs/releases/A.B.txt``?
  222. * Is there documentation for the feature and is it :ref:`annotated
  223. appropriately <documenting-new-features>` with
  224. ``.. versionadded:: A.B`` or ``.. versionchanged:: A.B``?
  225. Deprecating a feature
  226. ---------------------
  227. See the :ref:`deprecating-a-feature` guide.
  228. All code changes
  229. ----------------
  230. * Does the :doc:`coding style
  231. </internals/contributing/writing-code/coding-style>` conform to our
  232. guidelines? Are there any ``black``, ``blacken-docs``, ``flake8``, or
  233. ``isort`` errors? You can install the :ref:`pre-commit
  234. <coding-style-pre-commit>` hooks to automatically catch these errors.
  235. * If the change is backwards incompatible in any way, is there a note
  236. in the release notes (``docs/releases/A.B.txt``)?
  237. * Is Django's test suite passing?
  238. All tickets
  239. -----------
  240. * Is the pull request a single squashed commit with a message that follows our
  241. :ref:`commit message format <committing-guidelines>`?
  242. * Are you the patch author and a new contributor? Please add yourself to the
  243. :source:`AUTHORS` file and submit a `Contributor License Agreement`_.
  244. .. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/