提交补丁

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

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

如果您正在修复一个非常微不足道的问题,例如更改文档中的一个单词,推荐的方法是使用 GitHub 提交拉取请求,而无需使用 Trac 工单。

有关如何使用拉取请求的更多详细信息,请参见: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 工单追踪系统中创建一个。
  • 如果此问题已有相关工单,请确保没有其他人认领。要做到这一点,查看工单的 " Owned by "(负责人)部分。如果它被分配给了 " nobody "(无人认领),那么它可以被认领。否则,可能已经有其他人正在处理此工单。您可以选择另一个错误或功能来处理,或者联系负责此工单的开发人员提供帮助。如果一个工单在数周或数月内没有任何活动,那么将其重新分配给自己可能是安全的。
  • 如果您尚未登录,请点击工单页面左上方的 " GitHub 登录" 或 " DjangoProject 登录" 来登录您的账户。
  • 通过点击页面底部附近的 " Action " 下方的 " assign to myself " 单选按钮来认领工单,然后点击 " Submit changes " 提交更改。

备注

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

工单发表者的责任

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

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

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

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

应该发布哪类工单?

在某些情况下,执行认领工单的步骤可能过于繁琐。

对于一些小的改动,比如文档中的错别字或只需要几分钟修复的小错误,您无需进行认领工单的繁琐步骤。直接提交您的补丁即可完成!

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.

如果由于某种原因无法发送拉取请求,您还可以在 Trac 中使用补丁。在使用这种方式时,请遵循以下准则。

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

不一般的补丁

一个“非微小”的补丁是指不仅仅是修复小错误的补丁。它是一个引入 Django 功能并做出某种设计决策的补丁。

If you provide a non-trivial patch, include evidence that alternatives have been discussed on the Django Forum or django-developers list.

如果你不确定你的补丁是否应该被认为是非微小的,请在票务系统上征求意见。

弃用一个功能

Django 中的代码可能被弃用的原因有几个:

  • 如果一个功能在与向后兼容性不兼容的方式下进行了改进或修改,旧的功能或行为将被弃用。
  • 有时,Django 会包含一个 Python 库的后移版本,而该库在 Django 当前支持的 Python 版本中不包含。当 Django 不再需要支持不包含该库的旧版本 Python 时,该库将在 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. 在一个特定的测试中:

    from django.test import ignore_warnings
    from django.utils.deprecation import RemovedInDjangoXXWarning
    
    
    @ignore_warnings(category=RemovedInDjangoXXWarning)
    def test_foo(self):
        ...
    
  2. 对于整个测试用例:

    from django.test import ignore_warnings
    from django.utils.deprecation import RemovedInDjangoXXWarning
    
    
    @ignore_warnings(category=RemovedInDjangoXXWarning)
    class MyDeprecatedTests(unittest.TestCase):
        ...
    

您还应该为弃用警告添加一个测试:

from django.utils.deprecation import RemovedInDjangoXXWarning


def test_foo_deprecation_warning(self):
    msg = "Expected deprecation message"
    with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
        # invoke deprecated behavior
        ...

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,
    )
    old_private_helper()
    ...

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 补丁

For information on JavaScript patches, see the JavaScript 补丁 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, mergers 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 merger, 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?

弃用一个功能

See the 弃用一个功能 guide.

All code changes

  • Does the coding style conform to our guidelines? Are there any black, blacken-docs, flake8, or isort 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