File: submitting-patches.txt

package info (click to toggle)
python-django 3%3A5.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 61,236 kB
  • sloc: python: 361,585; javascript: 19,250; xml: 211; makefile: 182; sh: 28
file content (443 lines) | stat: -rw-r--r-- 18,688 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
========================
Submitting contributions
========================

We're always grateful for contributions to Django's code. Indeed, bug reports
with associated contributions will get fixed *far* more quickly than those
without a solution.

.. _trivial-change:

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 :doc:`working-with-git` 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`_. Remember that proposals for new features should follow
  the :ref:`process for suggesting new features <requesting-features>`.

* 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. Once logged
  in, you can then click the "Modify Ticket" button near the bottom of the
  page.

* Claim the ticket by clicking the "assign to" radio button in the "Action"
  section. Your username will be filled in the text box by default.

* Finally click the "Submit changes" button at the bottom to save.

.. note::
    The Django software foundation requests that anyone contributing more than
    a :ref:`trivial change <trivial-change>`, 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.

.. _Login using your GitHub account: https://code.djangoproject.com/github/login
.. _Create an account: https://www.djangoproject.com/accounts/register/
.. _password reset page: https://www.djangoproject.com/accounts/password/reset/
.. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/

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 changes directly and you're done!

It is *always* acceptable, regardless whether someone has claimed it or not, to
link proposals to a ticket if you happen to have the changes ready.

.. _patch-style:

Contribution 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 solution, but it is not the only part. A good fix should also include a
  :doc:`regression test <unit-tests>` 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 adds a new feature, or modifies the behavior of an existing
  feature, the change should also contain documentation.

When you think your work is ready to be reviewed, send :doc:`a GitHub pull
request <working-with-git>`.
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 diff`` command.

* 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 ``.diff`` extension; 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 :ref:`contribution
  checklist <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`_.

.. _ticket tracker: https://code.djangoproject.com/
.. _Development dashboard: https://dashboard.djangoproject.com/

Contributions which require community feedback
==============================================

A wider community discussion is required when a patch introduces new Django
functionality and makes some sort of design decision. This is especially
important if the approach involves a :ref:`deprecation <deprecating-a-feature>`
or introduces breaking changes.

The following are different approaches for gaining feedback from the community.

The new feature ideas tracker
-----------------------------

If you have an idea for a new feature, please create a new proposal (or join an
existing discussion) following the :ref:`process for suggesting new features
<requesting-features>`. You should explain the need for the change, go into
details of the approach and discuss alternatives.

The Django Forum
----------------

You can propose a change (that is not a new feature idea) on the
`Django Forum`_. You should explain the need for the change, go into details of
the approach and discuss alternatives.

Please include a link to such discussions in your contributions.

Third party package
-------------------

Django does not accept experimental features. All features must follow our
:ref:`deprecation policy <internal-release-deprecation-policy>`. Hence, it can
take months or years for Django to iterate on an API design.

If you need user feedback on a public interface, it is better to create a
third-party package first. You can iterate on the public API much faster, while
also validating the need for the feature.

Once this package becomes stable and there are clear benefits of incorporating
aspects into Django core, the next step is to propose its inclusion by
following the :ref:`process for suggesting new features <requesting-features>`.

Django Enhancement Proposal (DEP)
---------------------------------

Similar to Python’s PEPs, Django has `Django Enhancement Proposals`_ or DEPs. A
DEP is a design document which provides information to the Django community, or
describes a new feature or process for Django. They provide concise technical
specifications of features, along with rationales. DEPs are also the primary
mechanism for proposing and collecting community input on major new features.

Before considering writing a DEP, it is recommended to first open a discussion
following the :ref:`process for suggesting new features <requesting-features>`.
This allows the community to provide feedback and helps refine the proposal.
Once the DEP is ready the :ref:`Steering Council <steering-council>` votes on
whether to accept it.

Some examples of DEPs that have been approved and fully implemented:

* `DEP 181: ORM Expressions <https://github.com/django/deps/blob/main/final/0181-orm-expressions.rst>`_
* `DEP 182: Multiple Template Engines <https://github.com/django/deps/blob/main/final/0182-multiple-template-engines.rst>`_
* `DEP 201: Simplified routing syntax <https://github.com/django/deps/blob/main/final/0201-simplified-routing-syntax.rst>`_

.. _Django Forum: https://forum.djangoproject.com/
.. _Django Enhancement Proposals: https://github.com/django/deps

.. _deprecating-a-feature:

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 :ref:`deprecation policy<internal-release-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 :ref:`running the
test suite <running-unit-tests>` 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) as ctx:
            # invoke deprecated behavior
            ...
        self.assertEqual(ctx.filename, __file__)

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,
            stacklevel=2,
        )
        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.B`` annotation. 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 :term:`feature release <Feature release>`, all
``RemovedInDjangoXXWarning``\s matching the new version are removed.

Testing with a Django project
=============================

It's important to test local changes using a Django project. This allows
ensuring that the changes behave as expected in a real environment, especially
for user-facing features such as templates, forms, or the admin.

To do this:

#. Create a virtual environment and :ref:`install the cloned copy of Django in
   editable mode <intro-contributing-install-local-copy>`.

#. Set up a Django project outside the source tree (you can use the :doc:`first
   part of the tutorial </intro/tutorial01>` for guidance).

With this setup, any changes made to the Django checkout will take effect
immediately in the test project, allowing manual testing of contributions
against a new or existing app.

JavaScript contributions
========================

For information on JavaScript contributions, see the :ref:`javascript-patches`
documentation.

Optimization patches
====================

Patches aiming to deliver a performance improvement should provide benchmarks
showing the before and after impact of the patch and sharing the commands for
reviewers to reproduce.

.. _django-asv-benchmarks:

``django-asv`` benchmarks
-------------------------

`django-asv`_ monitors the performance of Django code over time. These
benchmarks can be run on a pull request by labeling the pull request with
``benchmark``. Adding to these benchmarks is highly encouraged.

.. _django-asv: https://github.com/django/django-asv/

.. _patch-review-checklist:

Contribution checklist
======================

Use this checklist to review a pull request. If this contribution would not be
:ref:`considered trivial <trivial-change>`, first ensure it has an accepted
ticket before proceeding with the review.

If the pull request passes all the criteria below and is not your own, 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 changes or bump it back to "Accepted" if further
work needs to be done.

If you're looking to become a member of the `triage & review team
<https://www.djangoproject.com/foundation/teams/#triage-review-team>`_, doing
thorough reviews of contributions 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 <https://dashboard.djangoproject.com/>`_.

Looking to get your pull request 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``, or
  ``make.bat html`` on Windows, from the ``docs`` directory)?
* Does the documentation follow the writing style guidelines in
  :doc:`/internals/contributing/writing-documentation`?
* Are there any :ref:`spelling errors <documentation-spelling-check>`?

Bugs
----

* Is there a proper regression test (the test should fail before the fix
  is applied)?
* If it's a bug that :ref:`qualifies for a backport <supported-versions-policy>`
  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 :ref:`annotated
  appropriately <documenting-new-features>` with
  ``.. versionadded:: A.B`` or ``.. versionchanged:: A.B``?

Deprecating a feature
---------------------

See the :ref:`deprecating-a-feature` guide.

All code changes
----------------

* Does the :doc:`coding style
  </internals/contributing/writing-code/coding-style>` conform to our
  guidelines? Are there any  ``black``, ``blacken-docs``, ``flake8``, or
  ``isort`` errors? You can install the :ref:`pre-commit
  <coding-style-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?
* If the change affects the Django admin or rendered HTML output, has
  :ref:`accessibility testing <accessibility-testing-baseline>` been done?

All tickets
-----------

* Is the pull request a single squashed commit with a message that follows our
  :ref:`commit message format <committing-guidelines>`?
* Are you the patch author and a new contributor? Please add yourself to the
  :source:`AUTHORS` file and submit a `Contributor License Agreement`_.
* Does this have an accepted ticket on Trac? All contributions require a ticket
  unless the :ref:`change is considered trivial <trivial-change>`.

.. _Contributor License Agreement: https://www.djangoproject.com/foundation/cla/