Django: Using get_or_create to prevent race conditions

get_or_create, is an awesome helper utility to have at your disposal when you need an object matching some specifications, but there should only be exactly one match — you want to retrieve it if it already exists, and create it if it doesn’t.

However, there’s a scenario where it doesn’t quite do what we expect in the case of race conditions (exactly the thing we’re…