django / django/new-features

Support generator checks

Open
#199 1 comment 8 reactions 0 assignees View on GitHub
Checks Django Core
Dominant language
No language data
Stars
188
Forks
7
PR merge metrics
No merged PRs in 30d

Description

### Code of Conduct

- [x] I agree to follow Django's Code of Conduct

### Feature Description

Add official support for generator-style system checks:

```python
@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:

```python
@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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating Django's system-check registration and execution paths, then inspect the existing check tests and documentation. Add coverage for generator-style checks for each check type and document the supported form; done means generators yield the same errors and warnings as list-returning checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.