logo
podcast Podcast
get help Get Unstuck

How to make a bug fix way more valuable

Fixing bugs is important, but by taking just a little more time you can make your app much more resilient

Joel Clermont
Joel Clermont
2023-09-05

Recently, I was fixing an N+1 issue that made its way into production (hooray Sentry for reporting it!). The actual fix was quite easy, just eager loading a couple relationships. But it annoyed me that I didn't find this in testing. I did have lazy loading protection enabled, and I had test coverage of the code, but the setup portion of the test didn't create multiple related records, so the tests couldn't catch the N+1 problem.

But before I added the one-line eager loading fix, I updated my test so that it triggered the lazy loading protection. Not only did this give me verification once I fixed the problem, but it made sure I wouldn't break it in the future. The earlier you find bugs, the more stable your app is. I'd rather find it during local development than in production. And yes, I consider poor performing code (like N+1 problems) to be a bug.

If you're fixing a bug today, can you take an extra few minutes and write a failing test before fixing the bug? Do this enough times, and your app becomes very resilient to regressions.

Here to help,

Joel

P.S. We all get stuck sometimes! Need a quick pairing session with a Laravel expert to get unstuck?

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.