提交补丁

我们总是感谢Django代码的补丁。确实,具有相关补丁的错误报告将比没有补丁的错误报告 快地得到修复。

错字修复和琐碎的文档更改

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.

有关如何使用拉取请求的更多详细信息,请参见:doc:working-with-git

“发布”工单

在一个全球有数百个贡献者的开源项目中,有效地管理沟通以避免重复工作并尽可能提高贡献者的效率是非常重要的。

因此,我们的政策是供贡献者“发布”工单,以便让其他开发人员知道正在处理特定的错误或功能。

如果您确定了要做出的贡献并且有能力解决(通过编程能力,Django内核知识水平和时间可用性来衡量),请按照以下步骤进行发表:

  • 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.
  • 如果尚无此问题的工单,请在我们的 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."

注解

Django软件基金会要求对Django贡献不小的补丁的人签署并提交 Contributor License Agreement 贡献者许可协议,以确保Django软件基金会对所有贡献都拥有明确的许可,从而为所有用户提供明确的许可。

工单发表者的责任

发布工单后,您有责任以合理及时的方式处理该工单。 如果您没有时间来处理它,请先取消发布或不发布它!

如果一两周内没有任何关于特定已发布工单的进展迹象,则另一位开发人员可能会要求您放弃该发布了的工单,以使其不再被垄断,而其他人也可以发布。

如果您已发布工单,并且要花很长时间(几天或几周)编写代码,请通过在工单上发布评论来使每个人都保持最新状态。如果您不提供定期更新,并且不响应进度报告的请求,则您对工单的要求可能会被撤消。

与往常一样,多交流好过少交流!

应该发布哪类工单?

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.

补丁的风格

确保您所做的任何贡献至少满足以下要求:

  • 解决问题或添加功能所需的代码是补丁的重要组成部分,但不是唯一的部分。 一个好的补丁程序还应该包括一个 regression test 1 回归测试以验证已修复的行为并防止问题再次出现。 另外,如果某些工单与您编写的代码相关,请在测试中的一些注释中提及工单编号,以便在提交补丁程序并关闭工单后可以轻松地追溯相关的讨论。
  • 如果与修补程序关联的代码添加了新功能或修改了现有功能的行为,则该修补程序还应包含文档。

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 diff command.
  • 使用“附加文件”按钮将补丁附加到 ticket tracker 工单跟踪系统中的工单上。 除非是单行补丁,否则请 不要 将补丁放入工单描述或注释中。
  • 用扩展名 .diff 命名补丁文件; 这将使工单跟踪系统应用正确的语法突出显示,这非常有帮助。

无论您以何种方式提交工作成果,请按照以下步骤操作。

  • 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.

不一般的补丁

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 django-developers.

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:

  1. In a particular test:

    from django.test import ignore_warnings
    from django.utils.deprecation import RemovedInDjangoXXWarning
    
    @ignore_warnings(category=RemovedInDjangoXXWarning)
    def test_foo(self):
        ...
    
  2. 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 can 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

Finally, there are a couple of updates to Django's documentation to make:

  1. 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.
  2. 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.
  3. 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, committers 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 committer, 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.

文档

  • 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 编写文档?
  • 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.B or .. 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 flake8 errors? 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