graphql-ruby-fragment_cache icon indicating copy to clipboard operation
graphql-ruby-fragment_cache copied to clipboard

Rails 7.1 deprecation notice for `cache_format_version` in Rails `test` environment

Open asgeo1 opened this issue 1 year ago • 5 comments

This line of code in this gem, is producing a deprecation warning with Rails 7.1

https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/blob/1c08b1fe38508cc3388036d66153c45cd469d917/lib/graphql/fragment_cache/railtie.rb#L28

But only in the test environment.

DEPRECATION WARNING: Support for `config.active_support.cache_format_version = 6.1` has been deprecated and will be removed in Rails 7.2

It doesn't matter if you set config.active_support.cache_format_version = 7.1 in the Rails environment or intializer, the deprecation warning will still happen.

This is because that line of code is executing before Rails gets a chance to boot and set the correct cache_format_version.

If using RSpec, a possible workaround for now, is in rails_helper.rb to set the cache format version prior to the gem being loaded. e.g.

require "spec_helper"

# NOTE: this is a fix for graphql-fragment_cache, which is initializing it's own cache in the test environment
require "active_support/cache"
ActiveSupport::Cache.format_version = 7.1

require File.expand_path("../config/environment", __dir__)
require "rspec/rails"

RSpec.configure do |config|
  ...

asgeo1 avatar May 09 '24 05:05 asgeo1

I can confirm this is still an issue in latest rails version (v7.1.3.4) along with latest graphql-ruby-fragment_cache version (v1.20.2)

The line where the warning happens is now different though: https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/blob/8ce934d1ab3bfd07e01fe387bf903ef75489bbe4/lib/graphql/fragment_cache/railtie.rb#L22

For now I'm using the suggested workaround as well (setting format_version before the gem is loaded in test environment).

Drowze avatar Jul 18 '24 13:07 Drowze

@DmitryTsepelev Rails 7.2 is out and the cache_format_version was removed.

noma4i avatar Aug 29 '24 05:08 noma4i

@asgeo1 @Drowze @noma4i Hey! This should probably be a fix https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/pull/118. I do not have any app that uses the gem right now, could you please try the fix out before I merge it in?

DmitryTsepelev avatar Sep 08 '24 10:09 DmitryTsepelev

Fix is here #119, will be a part of the next release, thanks @noma4i 🙂

DmitryTsepelev avatar Sep 14 '24 08:09 DmitryTsepelev

Just upgraded from 1.20.2 to 1.20.4 and it ~seems fixed now~! Thank you! 😄

EDIT: ops! too early! It seems the warning is back: Screenshot 2024-10-16 at 07 55 39

The issue is that Rails.application evaluates to nil at the time the railtie is loaded. I think simply adding a initializer block should fix the problem (so setting the cache store to null happens as part of the rails initialization process, after Rails.application is actually defined).

Tried to tackle this issue and opened PR at #120 😃

Drowze avatar Oct 14 '24 16:10 Drowze