An irritating Django feature
by mark | 17 Nov 2022, 7:34 p.m.
I have made some backend changes to the payslip thingy. (You won't notice - it just makes it easier to allow for within-year parameter changes, like the movements on primary threshold and contribution rates we have seen with NI this year).
I had it all set up and tested nicely. Then it failed pushing to heroku with psycopg2.errors.UndefinedTable
errors. Oh no!
What had happened: I had used data migrations to create and fill the new DB tables. I then included a thing in the form that would pull the latest year from the tables as the default. this was the problem. Pulling a number from a table will fail if the table doesn't exist, which it won't at that point in the __init__()
cycle, as the migrations haven't yet run. Urgh. So I had to do an ugly hotfix to replace a table lookup with a bare number to get it to deploy. Now it exists I can put in the code I wanted to. But I don't want to right now.
Lesson learned: test by migrating the app to zero and restarting the web server before deploy. This will throw any init-needs-something-to-exist-which-hasn't-yet-been-init'd errors before you deploy. It's basically a race condition.
Back to all articles