Developer Note: Fixing a site-breaking bug

I'm a relative newbie when it comes to writing code. I make newbie mistakes. Usually I'll catch site-crippling errors pretty early. But there's one particular bug I just squashed that's broken the site for some users, likely since launch.

The Issue: Language Codes

If you don't have English set as your default browser language, then you might have noticed that we'll search for courses in your local language first. And if you can understand another language, you might have tried setting your language manually yourself to something else.

Let's find some courses in Italian.

But what happens when your language isn't supported? What if you're browsing from a computer whose browser is set to, say, Khmer?

I'm so sorry.

For all I know, there could have been thousands of international users who wanted to get on the site, but couldn't. They couldn't even get far enough to manually set their language. And to think, the whole reason why I built in support for languages was to appeal to a larger international community.

So what went wrong?

I didn't handle an exception properly.

Worse, I would have known about this issue months ago after launch had I just checked the error logs and noticed all of the complaints about languages.

gunicorn[17365]: models.LanguageDoesNotExist: Instance matching query does not exist [...]

And like most insidious errors, I only had to make a few minor tweaks to fix the issue. This particular language code problem took <20 characters of changes to one line to resolve. It involves handling an exception for models.DoesNotExist, specific to Python's Peewee ORM.

What's changed?

If you've been using OpenCourser normally for the past few weeks, nothing's changed. But if your language code falls outside of the ones listed below, you should now be able to view OpenCourser just fine.

  • English (EN)
  • Spanish (ES)
  • French (FR)
  • Portuguese (PT)
  • German (DE)
  • Italian (IT)
  • Chinese (ZH)
  • Arabic (AR)
  • Korean (KO)
  • Japanese (JA)
  • Hindi (HI)
  • Dutch (NL)
  • Finnish (FI)
  • Swedish (SV)
  • Norwegian (NO)
  • Russian (RU)
  • Turkish (TR)
  • Hebrew (HE)

Experience any bugs? Drop a comment below :)


Read more posts by this author.

Subscribe to Learn More

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!