This is very perplexing, because it's breaking on my laptop with my local test instance as well, which has a separate database, even with older versions of the code. How long has it not been possible to look at things? It might take me a minute to crack this bug.
Edit: I am even more confused about the cause of this after my debugging session. The conditions are very strange. Whatever the root of the problem might be, I may never know, but I headed it off by adding a None check in a place where one should be anyway. The code works again.