Finding the Best Posts

See my top posts page for a selection of my best posts. Or search the site with Duck Duck Go:

Recent Posts

How to Run a Django Migration “By Hand”

You can lead a pegasus to the database, but you can’t force it to migrate.

Normally your Django project’s deploy process runs the migrate command, and that takes care of updating your database as necessary. Especially on smaller databases, Django’s migration system can “just do it” for you.


How to Patch Requests to Have a Default Timeout

Summon forth the armies, but with a timeout of five seconds.

Python’s requests package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does.


How to optimize PostgreSQL queries from Django using pgMustard

Well, that cuts the mustard.

Slow queries happen, and when they do, it can be tough to dissect why they’re slow. This difficulty is compounded by using Django’s ORM, since it generates the SQL for you, so you may have little idea of the actual queries “under the hood”.


Shell Tricks for Repeatedly Running Flaky Tests

shell be coming round the mountain when shell comes

Investigating flaky tests is a dull necessity of testing. At least it is (in the best case) infrequent. Here are some shell commands you can use to automate steps in your investigations. These will work on (at least) bash and zsh.


How to Find and Stop Running Queries on PostgreSQL

Owl be stopping those pesky queries!

Your PostgreSQL server is seizing up, with some naughty queries consuming too many resources or blocking others. Don’t panic! You can stop those problem queries and stabilize your system.


Mike Acton’s Expectations of Professional Software Engineers

grumpy cats ranting

In a 2019 talk/rant titled “Everyone Watching This Is Fired”, games industry veteran Mike Acton rattled off a sample of 50 things he expects of developers he works with. The title refers to his tongue-in-cheek suggestion that anyone who doesn’t meet all these requirements would be immediately fired.


How to Clean Up Unused Code With Git

Time to go digging through your project’s ancient history…

Projects often accumulate an amount of unused code. This cruft makes a prjoect harder to navigate, and can confuse future development or debugging.


How to Be a Teapot in Django

Lift me up, and pour me out.

HTCPCP, or Hyper Text Coffee Pot Control Protocol, was published as an April Fool’s joke 24 years ago today. It’s an HTTP extension for controlling coffee pots, and whilst it is a joke, it appears in various places around the web.


How to Make Django Raise an Error for Missing Template Variables

Who dropped the {{ variable }} ?

It’s all too easy to forget to pass a variable to your template, or make a typo in a variable name. Unfortunately, it can be quite hard to debug such mistakes, since Django’s default behaviour is to ignore the problem and render an empty string.


You Probably Don’t Need Django’s get_user_model()

Which way to the User model?

Django’s authentication system, django.contrib.auth, provides a built-in User model class. You can swap this to a different class with the AUTH_USER_MODEL setting, most easily at the start of the project.