Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

The Django Patterns We See Most

Last updated:

The five most common

  1. Query multiplication — lazy loading in loops
  2. Record-level permissions missing — action checked, ownership not
  3. Debug left on in production
  4. Email through the default backend, silently not arriving
  5. No tests around the business rules and permissions
The second is the most serious. A user permitted to view orders viewing someone else's order is a data breach, and it is depressingly common.

Five more

  • Business logic in views, so it cannot be reused or tested
  • Fat models with everything in save methods, so ordering matters and nothing is clear
  • Secrets in settings committed to the repository
  • Media served from the code directory
  • Migrations edited after being applied somewhere

Costs

MistakeTypical cost
Query multiplicationPages that take ten seconds
Missing record permissionsA data breach
Debug in productionFull exposure of settings and queries
Default email backendMonths of lost enquiries
No testsChanges take three times as long

All fixable without a rewrite

Every one of these is addressable incrementally in an existing application. None requires replacement, which is worth knowing before anyone proposes one.

Fix the permissions and the production settings first — those are the ones with the most serious consequences.

How to find them

  1. Run Django's deployment check — seconds, catches configuration
  2. Log query counts per page — finds multiplication immediately
  3. Try to access another user's record — finds permission gaps
  4. Send yourself an email from production — checks delivery
  5. Look for tests around the calculations — usually absent

Frequently asked questions

Which should we fix first?

Record-level permissions and production settings. Those have the most serious consequences.

How do we find query multiplication?

Log the count per request. Any page issuing more than a few dozen is worth investigating.

Can these be fixed incrementally?

All of them. None requires a rewrite.

How do we prevent them recurring?

Tests, the deployment check in the pipeline, and query count assertions on list views.

Keep reading

Recognise more than three of these?

Most inherited applications have them. Permissions first — that is where the exposure is.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning