palkan/store_attribute

_lookup_cast_type removed in Rails 7 alpha

Closed this issue · 3 comments

Tell us about your environment

Ruby Version: 2.7.2

Rails Version: 7.0.0.alpha (from GitHub)

PostgreSQL Version: 13.3

Store Attribute Version: (Latest from GitHub)

What did you do?

We've started looking at using our application at work using Rails 7 from GitHub, while using store_attribute in our models. In doing so, it raised some errors from underlying changes to ActiveRecord.

For full transparency, this is how a few of our store_attribute calls look:

  store_attribute :greeting, :title, :string, prefix: :greeting
  store_attribute :greeting, :description, :string, prefix: :greeting
  store_attribute :greeting, :video, :json, prefix: :greeting

What did you expect to happen?

The error to not be raised :) (though to be fair, it makes sense why the error happens)

What actually happened?

An error was raised (both in the browser and the Rails console)

NoMethodError: undefined method `_lookup_cast_type' for #<Class:0x00007fd1b53d5430>

I tracked it down by removing the store_attributes in our model, and things behaved like expected, when I dug deeper into the gem source I believe this is the only occurrence of using the removed method from Rails 7.

Type::TypedStore.create_from_type(_lookup_cast_type(attr_name, was_type, {}), name, type, **options)

Here is the PR with the removal of this method from Rails: https://github.com/rails/rails/pull/39929/files#diff-2a6a5a31a6210a1e7036784fb31c738e1d2874bb5ae123d03737db02cb198876L290-L300

I wasn't quite sure how would be best to fix the gem for backwards compatibility, so thanks in advance!

Thanks for reporting!

ActiveRecord changes fast; let me take a look...

Should be fixed by 6848ccb

Could you please check?

(I'm not going to publish a release yet; let's wait at least for the Rails 7 beta).

Thanks @palkan I've confirmed that 6848ccb does indeed fix Rails 7 support. Things seem to be working great as far as I can tell now.

Appreciate the fix!