ORM Lens

DOL002 — Prefer not .exists() over .count() == 0

Default severity: info · Applicability: safe · Category: queryset

Detects qs.count() == 0 used to test for emptiness. Counting all matching rows just to compare against zero does far more work than asking the database whether at least one row exists — .exists() translates to SELECT 1 ... LIMIT 1, no row count required. The rewrite is semantically identical, so the QuickFix (“Rewrite to not .exists()”) is eligible for auto-apply and “Fix All”.

Bad

if Order.objects.filter(user=user).count() == 0:
    show_empty_state()

Good

if not Order.objects.filter(user=user).exists():
    show_empty_state()

Suppress

# orm-lens-disable-next-line DOL002

Or per-workspace in .vscode/settings.json: {"djangoOrmLens.rules": {"DOL002": "off"}}.