From 522287ed53a17247ebe4772ad221aa0dff271952 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Wed, 28 Feb 2024 13:30:55 -0800 Subject: [PATCH] Fix MissingAttributeError in `ClosetHanger#merge_quantities` Oh rough, when moving an item list entry from one list to another, our logic to merge their quantities if it's already in that list was just fully crashing! That is, moves without anything to merge were working, but moves that required a merge were raising Internal Server Error 500, because the `list_id` attribute wasn't present. I'm not sure why this ever worked, I'm assuming using `list_id` in the `where` condition would include it in the `select` implicitly in a previous version of Rails? Or maybe Rails used to have fallback behavior to run a second query, instead of raising `MissingAttributeError` like it does now? Well, in any case, this seems to fix it! Whew! --- app/models/closet_hanger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/closet_hanger.rb b/app/models/closet_hanger.rb index 1247589c..fcdbc2c0 100644 --- a/app/models/closet_hanger.rb +++ b/app/models/closet_hanger.rb @@ -203,7 +203,7 @@ class ClosetHanger < ApplicationRecord # hanger. Select enough for our logic and to update flex_source. # TODO: We deleted flex, does this reduce what data we need here? conflicting_hanger = self.class.select([:id, :quantity, :user_id, :item_id, - :owned]). + :owned, :list_id]). where(:user_id => user_id, :item_id => item_id, :owned => owned, :list_id => list_id).where(['id != ?', self.id]).first