If state is not getting updated look for rollback in your SQL logs

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

Last Updated: 2021-05-15

When I was writing code to merge two different products, I seemed to have issues getting the query cache to notice the notes_files in their new locations:

# Things tried
# 1.
Product.uncached do
 ...
end

# 2.
continued_product.subject.notes_files << retired_product.notes_files

# 3.
notes_files.each do |nf|
  nf.subject = continued_product.subject
  nf.save
end

I even tried updating rails, etc.

Turns out, I was silently having a validation error!

I would have noticed had I paid more attention to the logs where it said "Rollback". (To get alerted via explosions instead of logs, I should have used save! or called .valid?.)

Lesson

Watch for rollback in your SQL log