solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Deprecation warning from set_option_value in Rails 6.0.3.2

Open tmtrademarked opened this issue 5 years ago • 1 comments

There appears to be a deprecation warning emitted when calling variant.set_option_value in Rails 6.0.3.2. It looks like the code somewhere in Solidus is doing something potentially unsafe:

DEPRECATION WARNING: Class level methods will no longer inherit scoping from `new` in Rails 6.1. To continue using the scoped relation, pass it into the block directly. To instead access the full set of models, as Rails 6.1 will, use `Spree::OptionValue.default_scoped`.

Solidus Version: 2.10.0

To Reproduce Seems to occur for me whenever my code invokes variant.set_option_value, although I'm specifically noticing it in my specs. Possible that something about the test code loading path is different, although that would surprise me given the warning.

tmtrademarked avatar Jun 30 '20 13:06 tmtrademarked

This is most likely caused by this:

option_value = Spree::OptionValue.where(option_type_id: option_type.id, name: opt_value).first_or_initialize do |option|
  option.presentation = opt_value
  option.save!
end

I'm not 100% sure, but we may try calling save! outside of the first_or_initialize block (or, even simpler, use first_or_create!) instead.

aldesantis avatar Jul 01 '20 07:07 aldesantis