Deprecated QuerySet.extra() usage
Part of Security, which counts for 30% of the overall score. When this check fires it deducts 8 points from that category, once per scan, no matter how many places it turns up.
What it detects
QuerySet.extra() accepts raw SQL fragments for select/where/order_by clauses with much weaker escaping guarantees than the rest of the ORM, and the Django docs mark it deprecated in favor of expressions, F(), and Func(). Any request-derived text reaching an extra() argument is a SQL injection risk.
Why it matters
QuerySet.extra() accepts raw SQL fragments for its select, where, and order_by arguments with much weaker escaping guarantees than the rest of the ORM, and Django's own documentation marks it deprecated in favor of expressions, F(), and database functions. Any request-derived value that reaches an extra() argument is a SQL injection risk in the same way a raw cursor.execute() is.
How to fix it
Replace the extra() call with the modern ORM equivalent: annotate()/aggregate() with F() expressions and database functions (Func, Case, When) cover almost everything extra() used to be needed for. If a genuinely raw fragment is unavoidable, parameterize any interpolated value through the params argument rather than string-building the SQL fragment itself.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo