Fixed More Production Problems
For the second morning in a row, I had issues with production. Thankfully, this bug didn't effect any of the production data - only that data that was supposed to be written to Couch. So in a sense, it was bad, but not worthy of a re-run. The bug was pretty simple, and for once, I'm glad it wasn't me. The original code was:
def to_augmented_hash to_hash.delete('accounts').merge({ :category_counts => category_counts, :number_of_new_accounts => number_of_new_accounts }) end
where we were getting a NilClass error on the merge call. I had remembered reading that the delete() method would return a nil under some cases, so I looked it up again, and sure enough - it only returns the value of the key removed. What needed to happen was:
def to_augmented_hash to_hash.delete_if { |k,v| k == 'accounts' }.merge({ :category_counts => category_counts, :number_of_new_accounts => number_of_new_accounts }) end
With this in, it all worked just fine. When I went to check it in, I saw that a co-worker also fixed this, but split it out on several lines, and mutated the value with the delete(). I decided to leave mine in as it was cleaner, and more to the way it would have been re-written by someone else anyway.