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