Django ORM 6.1

Last reviewed Sep 24, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. Python 3155 lines · 3.8K tokens
  2. Django 6.1140 lines · 4.1K tokens
  3. Django ORM 6.191 lines · 3.5K tokens
Total386 lines · 11.4K tokens

CWE Coverage

  • 20
  • 23
  • 36
  • 59
  • 73
  • 78
  • 79
  • 89
  • 95
  • 117
  • 201
  • 203
  • 208
  • 209
  • 214
  • 250
  • 287
  • 295
  • 307
  • 319
  • 328
  • 338
  • 347
  • 352
  • 362
  • 367
  • 379
  • 384
  • 409
  • 416
  • 426
  • 427
  • 434
  • 470
  • 502
  • 521
  • 524
  • 532
  • 601
  • 611
  • 614
  • 639
  • 674
  • 732
  • 770
  • 772
  • 776
  • 778
  • 798
  • 807
  • 829
  • 862
  • 863
  • 915
  • 916
  • 918
  • 942
  • 1004
  • 1021
  • 1104
  • 1275
  • 1333
  • 1336
  • 1395

Prompt Preview

Apply the Django 6.1 prompt first. These rules extend that baseline for Django 6.1.1 ORM queries, relationships, field fetching, writes, transactions, and migrations.

Safe query construction

  • Use Value(user_value) for literal expression arguments; bare strings passed to Func are interpreted as field references. Resolve F() paths, lookup names, and ordering expressions from a server-owned registry.
  • Rebuild filter arguments from an allowlist instead of unpacking request dictionaries into Q(), filter(), exclude(), or get(). Keep connector choices, annotation aliases, and FilteredRelation definitions in trusted code.
  • Keep Func and Aggregate templates, function, arg_joiner, extra, extra_context, and output_field definitions trusted; these configure SQL generation and are not bound values. Return SQL and parameters separately from custom as_sql() implementations.
  • Keep placeholders unquoted in raw(), RawSQL, and cursor SQL; use params for values. Reapply tenant and permission predicates inside raw SQL because QuerySet.raw() ignores preceding filters and does not enforce read-only execution.
  • Put row limits in raw SQL itself; RawQuerySet indexing and slicing happen outside the database. Include needed fields explicitly so omitted columns cannot trigger unexpected deferred queries.
  • Validate and convert values to the column's intended type in MySQL/MariaDB raw SQL and custom get_prep_value() implementations; coercion can turn a comparison into an unintended match.
  • Review raw references to mixed-case annotation and join