choice_typos
Find Django queryset filters using literals that never match field choices, catching typos like "cancelled" vs "canceled". Scans your project to prevent zero-row results and invalid data writes.
Instructions
Literals compared against a field whose choices will never match them.
STATUS = [("canceled", "Canceled"), ...]
Order.objects.filter(status="cancelled")
Two Ls. Valid Python, valid SQL, zero rows, no exception, wrong forever.
Nothing in Django objects: `choices` is checked by `full_clean()`, which a
queryset never calls and `create()` never calls either - so the write side
is worse, and puts a value in the column the application does not believe
exists.
No existing tool finds this: django-stubs types the field as `str` rather
than a Literal union of its choices, so mypy is satisfied, and the DJ rules
do not read the model registry.
Only literals are checked - an enum member is the spelling that cannot go
wrong - and only equality and `in`, because `iexact` can legitimately match
a differently spelled value. `order.status == "..."` names no model, so it
is reported only when the literal is wrong for every model with a field of
that name.
Args:
search_path: directory to scan. Defaults to the configured project.
include_tests: also scan test files.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search_path | No | ||
| include_tests | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||