Skip to content

Support generator checks #199

Description

@codingjoe

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

Add official support for generator-style system checks:

@register()
def some_check():
    if condition:
        yield Error()
    if other_contition:
        yield Warning()

Problem

Currently, you always have to declare an errors list and append new error items, like so:

@register()
def some_check():
    errors = []
    if condition:
        errors.append(Error())
    if other_contition:
        errors.append(Warning())
    return errors

In some places, generators may work. In others, they don't.

While we can argue about the beauty generator-style checks, they are functionally different:

  • They don't allocate memory for lists.
  • You can only iterate over a generator instance once.

The former is a nice bonus. The latter has a benefit that passing stale check results along, or other state leaks, becomes much harder to fall victim to.

Request or proposal

proposal

Additional Details

No response

Implementation Suggestions

Document a generator-style check and one to the test suite for each check type.

I'd love to keep this lean and clean. If we want to rewrite internal checks, this can be done in a later patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ChecksEnhancements to the System Checks Framework.Django CoreThis idea is suitable for inclusion in Django itself.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions