Pay attention to types when debugging

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the workflows category.

Last Updated: 2022-12-01

I was debugging some failed tests in which I had an array of objects, only some of which seemed to validate.

reports.map do |report|
  FinancialTransactionsReport.create!(download: report)
end
class FinancialTransactionsReport < ApplicationRecord
  has_one_attached :download
  validates :download, attached: true
  ...
end

All three reports were valid, yet only the first would validate. I went on a wild goose chase, questioning how the Rails-built in ActiveStorage uses background jobs, as well as searching for possible leakage of blobs between my test cases.

It turned out the solution was simple:

The first object, which validated, was not an instance of FinancialTransactionsReport. It was, instead, an object with a similar name, something like PayPalFinancialTransactions. My eyes glazed over these blocky names, but I should have considered this possibility ("that the object I am working with is not the long I expect") before jumping to far-out conclusions.