Django 6.1.3

14.4 Where Django leaks

Directing AI agents with a model of Django internals

What six questions catch 90% of subtle bugs in agent-generated Django code before it reaches production?

Coding agents are extraordinarily good at writing idiomatic Django syntax — models, serializers, ModelForms, ModelAdmin subclasses, migrations, and TestCase suites that pass on the first run. Yet agents share the exact same blind spot as rushed human engineers: they reason one file at a time, relying heavily on older Django 3.x/4.x conventions, and rarely simulate what happens when two layers meet under production load, concurrency, or real rollbacks.

When you carry a concrete mental model of Django 6.1.3’s internals, you stop reading generated code line-by-line for syntax errors and start asking six targeted seam questions that catch almost every subtle production bug before merge.

1. Query count and fetch_mode: what SQL runs when the template renders?

Never accept a view, serializer, or ModelAdmin change just because the unit test returns HTTP 200. Ask:

2. Transaction and on_commit boundaries: what happens on ROLLBACK?

Whenever generated code saves models AND touches anything outside the database — enqueueing a django.tasks job, sending email, invalidating a shared cache, deleting a FieldFile, or calling an external API — ask:

3. Sync vs. async chain mode: is this endpoint actually running on the event loop?

Whenever an agent writes "async def" views or suggests moving to ASGI for performance, ask:

4. Cache keys, Vary, and process-local state: what leaks across users or workers?

Whenever generated code caches responses, modifies sessions, writes custom template Node subclasses, or stores attributes on a ModelAdmin or View, ask:

5. Migrations, ProjectState, and forms: what mutates in memory or locks tables?

Whenever an agent generates a migration or overrides BaseModelForm.clean, ask:

6. Test blind spots: what did Client() silently skip?

Whenever an agent delivers a green test suite, ask:


Every abstraction in Django earns its keep by hiding real mechanical complexity behind clean Python. Knowing what sits underneath — from WSGIHandler and URLResolver through ModelBase, SQLCompiler, atomic, NodeList, BaseForm, AdminSite, Task, and TestCase — does not mean fighting Django’s abstractions. It means trusting them right up to the exact line where they leak, and knowing immediately where to look in the source when they do.