Django ORM 6.1
Last reviewed Sep 24, 2026
Prompt Details
Prompt Composition
3prompts
- Python 3155 lines · 3.8K tokens
- Django 6.1140 lines · 4.1K tokens
- 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 toFuncare interpreted as field references. ResolveF()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(), orget(). Keep connector choices, annotation aliases, andFilteredRelationdefinitions in trusted code. - Keep
FuncandAggregatetemplates,function,arg_joiner,extra,extra_context, andoutput_fielddefinitions trusted; these configure SQL generation and are not bound values. Return SQL and parameters separately from customas_sql()implementations. - Keep placeholders unquoted in
raw(),RawSQL, and cursor SQL; useparamsfor values. Reapply tenant and permission predicates inside raw SQL becauseQuerySet.raw()ignores preceding filters and does not enforce read-only execution. - Put row limits in raw SQL itself;
RawQuerySetindexing 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