Skip to content

Conversation

@t27duck
Copy link

@t27duck t27duck commented Oct 26, 2025

Purpose

Rails 8.1 deprecated ActiveSupport::Configurable which this gem currently uses.

DEPRECATION WARNING: ActiveSupport::Configurable is deprecated without replacement, and will be removed in Rails 8.2.

You can emulate the previous behavior with `class_attribute`.

Changes

This replaces the use of ActiveSupport::Configurable with an ActiveSupport::OrderedOptions class attribute.

Caveats

Related GitHub issues

N/A

Additional helpful information

Context:

Failure:
ActiveModelSerializers::Test::SchemaTest#test_that_raises_with_a_invalid_json_body [/home/runner/work/active_model_serializers/active_model_serializers/test/active_model_serializers/test/schema_test.rb:129]:
Expected /A JSON text must at least contain two octets!|unexpected token at ''/ to match "unexpected end of input at line 1 column 1".

bin/rails test /home/runner/work/active_model_serializers/active_model_serializers/test/active_model_serializers/test/schema_test.rb:119
Context:

/home/runner/work/active_model_serializers/active_model_serializers/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:16:in `<module:LoggerThreadSafeLevel>': uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)

rails/rails#54621
Context:

warning: ostruct was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add ostruct to your Gemfile or gemspec to silence this warning.
Context:

warning: mutex_m was loaded from the standard library, but is not part of the default gems starting from Ruby 3.4.0.
You can add mutex_m to your Gemfile or gemspec to silence this warning.
/.rvm/rubies/ruby-3.4.7/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require': cannot load such file -- mutex_m (LoadError)
Context:

Failure:
ActiveModel::Serializer::ReflectionTest#test_no_href_in_vanilla_reflection [/.rvm/gems/ruby-3.4.7/gems/minitest-5.10.3/lib/minitest/assertions.rb:139]:
Expected /undefined method `href'/ to match # encoding: US-ASCII
"undefined method 'href' for an instance of ActiveModel::Serializer::HasOneReflection".
@wasifhossain
Copy link
Member

Thanks @t27duck for the PR!

Could you please rebase your branch on #2493 and then we check again, if CI is happy?

@t27duck t27duck changed the base branch from 0-10-stable to CI-ruby-3-4-rails-8-1 October 28, 2025 11:25
Rails 8.1 deprecated `ActiveSupport::Configurable` which this gem currently uses.

```
DEPRECATION WARNING: ActiveSupport::Configurable is deprecated without replacement, and will be removed in Rails 8.2.

You can emulate the previous behavior with `class_attribute`.
```

This replaces the use of `ActiveSupport::Configurable` with an `ActiveSupport::OrderedOptions` class attribute.
@t27duck t27duck changed the base branch from CI-ruby-3-4-rails-8-1 to 0-10-stable October 28, 2025 11:36
@t27duck
Copy link
Author

t27duck commented Oct 28, 2025

@wasifhossain Ok, I'm pretty sure I did it right.

@wasifhossain wasifhossain requested a review from bf4 October 28, 2025 15:22
@wasifhossain wasifhossain merged commit 56b0a26 into rails-api:0-10-stable Nov 3, 2025
19 checks passed
@serggl
Copy link

serggl commented Nov 5, 2025

@wasifhossain any change this will be published to rubygems soon?

@wasifhossain
Copy link
Member

@bf4 could you please help us on this?

I am not so sure if the changes are worthy enough to get a new version at this moment.

Until then, you may continue with this:

gem 'active_model_serializers', github: 'rails-api/active_model_serializers', branch: '0-10-stable'

@bjorntrondsen
Copy link

Thanks for fixing this 🙏

I am not so sure if the changes are worthy enough to get a new version at this moment

Every Rails 8.1 app gets a deprecation warning, and for Rails 8.2 v0.10.15 probably wont work at all, so I think that warrants a new release 🙂

Ref:
ActiveSupport::Configurable is deprecated without replacement, and will be removed in Rails 8.2.

@janko
Copy link

janko commented Nov 11, 2025

There is a bug in the current implementation, where the configuration object is shared across serializer subclasses. This is inherent behavior of class_attribute, which does copy if you use direct assignment (#config= in this case), but changing hashes or arrays directly doesn't have effect.

In rails/rails#53970 that replaced ActiveSupport::Configurable usage, there was also a config copy in the inherited hook using ActiveSupport::InheritableOptions. I think active_model_serializers should do the same.

In our app, we currently have this regression on 0-10-stable:

ActiveModelSerializers.config.adapter = :json_api

class FooSerializer < ActiveModel::Serializer
  config.adapter = :attributes
end

ActiveModelSerializers.config.adapter #=> :attributes

@ebaranowski
Copy link

I vote that this is a perfect reason for a release. It provides a fix to a warning that pops up on any rails command anyone does when using this gem. Pefect reason to have a release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants