---
django: 6.1.3 (f16e25dcb9fe55734ba4ea2b00ac34405b7df74a)
---

# Django 6.x shifts that trip up older mental models

Which architectural changes in Django 5.x and 6.1.3 invalidate habits learned from older tutorials and model training data?

Because most tutorials, Stack Overflow answers, and LLM training corpora are dominated by Django `3.x` and `4.x` code, engineers — and coding agents — routinely reach for patterns that Django `5.x` and **`6.1.3`** have either replaced, hardened, or deprecated. Here is the source-verified field guide to the modern baseline we proved across Chapters 1 through 14.

## Seven headline shifts in Django 6.1.3

1. **`QuerySet.fetch_mode` (`FETCH_ONE`, `FETCH_PEERS`, `FETCH_RAISE`, Chapter 7):** Django `6.1` introduces pluggable lazy-loading modes in `django/db/models/fetch_modes.py`. `FETCH_ONE` (`django/db/models/fetch_modes.py:FETCH_ONE`) preserves historical per-instance lazy loading; `FETCH_PEERS` (`django/db/models/fetch_modes.py:FETCH_PEERS`) tracks sibling instances hydrated in the same query via weak references (`"_state.peers"` on each model instance) and batches missing `ForeignKey`/deferred fields into one IN query automatically; and `FETCH_RAISE` (`django/db/models/fetch_modes.py:FETCH_RAISE`) raises `FieldFetchBlocked` (`django/core/exceptions.py:FieldFetchBlocked`) on any accidental lazy query — giving teams native N+1 enforcement without third-party packages! (Remember from section 14.2: reverse `ForeignKey` managers still require `prefetch_related`.)
2. **Native `django.tasks` framework (Chapter 12):** Django `6.0+` ships a first-class task abstraction — `Task` (`django/tasks/base.py:Task`), `TaskResult`, `TaskResultStatus`, and `TaskBackendHandler` — configured via `"settings.TASKS"` with `ImmediateBackend` (`django/tasks/backends/immediate.py:ImmediateBackend`) for development and `DummyBackend` (`django/tasks/backends/dummy.py:DummyBackend`) for tests. Tasks must be module-level functions (`validate_task`), arguments and return values pass through `normalize_json`, exceptions under `ImmediateBackend` are captured into `TaskError` (`status=FAILED`) rather than raised out of `enqueue()`, and production code still must pair `Task.enqueue` with `django.db.transaction.on_commit`.
3. **Built-in `ContentSecurityPolicyMiddleware` and `LazyNonce` (Chapter 5):** You no longer need third-party middleware to emit Content Security Policy headers or per-request script nonces. `ContentSecurityPolicyMiddleware` (`django/middleware/csp.py:ContentSecurityPolicyMiddleware`) attaches a `LazyNonce` (`django/utils/csp.py:LazyNonce`) per request (only generating entropy if a template actually renders the nonce!) and builds `"Content-Security-Policy"` and `"Content-Security-Policy-Report-Only"` headers from `"SECURE_CSP"` / `"SECURE_CSP_REPORT_ONLY"`.
4. **Composite primary keys (`CompositePrimaryKey`, Chapters 6 and 11):** Django `5.2+` adds `CompositePrimaryKey` (`django/db/models/fields/composite.py:CompositePrimaryKey`), allowing multi-column primary keys (`pk = models.CompositePrimaryKey("tenant_id", "story_id")`) resolved via `CompositeAttribute` tuples and tuple lookups (`TupleExact`, `TupleIn`). Note the boundary we saw in Chapter 11: `AdminSite.register` (`django/contrib/admin/sites.py:AdminSite.register`) explicitly rejects models with `"model._meta.is_composite_pk"` (`ImproperlyConfigured`).
5. **`SECRET_KEY_FALLBACKS` for zero-downtime key rotation (Chapters 5 and 11):** Signing (`TimestampSigner`), signed cookies, and `AbstractBaseUser.get_session_auth_fallback_hash` (`django/contrib/auth/base_user.py:AbstractBaseUser.get_session_auth_fallback_hash`) all verify incoming tokens against `"SECRET_KEY_FALLBACKS"` when the primary `"SECRET_KEY"` fails, then transparently re-sign/cycle sessions with the new primary key so rotating secrets no longer logs out every active user at once!
6. **Async ORM, `"request.auser"`, and `1,500,000`-iteration PBKDF2 (Chapters 3, 7, 11):** Django `6.1` ships native async counterparts across QuerySets (`aget`, `acount`, `afirst`, `asave`, `async for`), sessions (`aget`, `aset`, `aflush`), auth (`aauthenticate`, `alogin`, `alogout`, `"request.auser()"`), and signals (`asend` with `asyncio.TaskGroup`). Meanwhile `PBKDF2PasswordHasher` (`django/contrib/auth/hashers.py:PBKDF2PasswordHasher`) defaults to **`1,500,000` iterations** (`~488 ms` per login check), backed by `check_password_with_timing_attack_mitigation` (`django/contrib/auth/__init__.py:check_password_with_timing_attack_mitigation`) and `PBKDF2PasswordHasher.harden_runtime`.
7. **Database-level defaults (`Field.db_default`) & template partials (`PartialTemplate`, Chapters 6 and 10):** Modern models can push defaults down into SQL DDL via `db_default` (`DatabaseDefault`) instead of Python-only `default`, and `django/template/` natively supports inline named template fragments via `PartialTemplate` (`django/template/base.py:PartialTemplate`) without splitting partials into separate HTML files.

## Active `RemovedInDjango2028Warning` deprecations spotted in `6.1.3` source

While reading pinned Django `6.1.3` across this book, we hit **five** active deprecations slated for removal in Django `7.0` (`RemovedInDjango2028Warning`) that older code and generators still emit routinely:

- **`django.db.transaction.savepoint` (`django/db/transaction.py:savepoint`) → `django.db.transaction.savepoint_create` (`django/db/transaction.py:savepoint_create`)** — Chapter 9.
- **`ModelAdmin.list_select_related = True` → `False` or an explicit tuple of relation names**, checked in `ModelAdmin.__init_subclass__` (`django/contrib/admin/options.py:ModelAdmin.__init_subclass__`) — Chapter 11.
- **Double-dot template variable lookups (`"story..slug"`)**, warned in `Parser.parse` (`django/template/base.py:Parser.parse`) — Chapter 10.
- **`BaseDatabaseCreation.create_test_db(serialize=...)`** (`django/db/backends/base/creation.py:BaseDatabaseCreation.create_test_db`) — Chapter 13.
- **`DEFAULT_AUTO_FIELD` defaults to `BigAutoField`** across modern projects (and `MiddlewareMixin` remains a compatibility bridge in `django/utils/deprecation.py` rather than the preferred modern callable middleware pattern).

Knowing both how Django's layers connect and where Django `6.1` has moved gives you an immediate superpower when reviewing code — especially code written quickly by an AI coding agent. We close the book with a sharp six-question review protocol in [Directing AI agents with a model of Django internals](directing-agents.md).
