Skip to content

Fix Issue #1465: Rails 7.2 ActiveSupport::Deprecation compatibility#19

Merged
takaokouji merged 1 commit intomasterfrom
fix/rails72-activesupport-deprecation-1465
Jan 21, 2026
Merged

Fix Issue #1465: Rails 7.2 ActiveSupport::Deprecation compatibility#19
takaokouji merged 1 commit intomasterfrom
fix/rails72-activesupport-deprecation-1465

Conversation

@takaokouji
Copy link
Collaborator

Summary

Fixes JSONAPI-Resources#1465 by updating the deprecation warning system to be compatible with Rails 7.2, which made ActiveSupport::Deprecation.warn a private method.

Problem

In Rails 7.2, calling ActiveSupport::Deprecation.warn as a class method raises:

NoMethodError: private method 'warn' called for class ActiveSupport::Deprecation

This breaks deprecation warnings throughout the gem, causing failures during rails app:update and normal operation.

Root Cause

Rails 7.2 changed ActiveSupport::Deprecation.warn from a public class method to a private method, requiring users to instantiate the Deprecation class first.

Solution

Updated JSONAPI.warn_deprecated helper to:

  1. Try calling as class method (Rails < 7.2)
  2. On NoMethodError, create instance and call warn on it (Rails 7.2+)
  3. Fallback to Kernel#warn for non-Rails environments
def self.warn_deprecated(message)
  if defined?(ActiveSupport::Deprecation)
    begin
      ActiveSupport::Deprecation.warn(message)
    rescue NoMethodError
      # Rails 7.2+
      version = defined?(JSONAPI::Resources::VERSION) ? JSONAPI::Resources::VERSION : '0.11.0'
      deprecation = ActiveSupport::Deprecation.new(version, 'jsonapi-resources')
      deprecation.warn(message)
    end
  else
    warn "[DEPRECATION] #{message}"
  end
end

Testing

  • All 694 tests pass
  • Added tests to verify deprecation system works correctly
  • Compatible with Rails 6.1+ through 7.2+

Related

🤖 Generated with Claude Code

…n compatibility

Issue JSONAPI-Resources#1465 reported NoMethodError when calling ActiveSupport::Deprecation.warn
in Rails 7.2, which made this method private.

Changes:
- Updated JSONAPI.warn_deprecated to use try/rescue approach
- Rails < 7.2: Calls ActiveSupport::Deprecation.warn as class method
- Rails 7.2+: Creates Deprecation instance and calls warn on it
- Fallback: Uses Kernel#warn for environments without ActiveSupport

The fix ensures backward compatibility while supporting Rails 7.2+.

Tests added to verify the deprecation warning system works correctly
across different Rails versions.

Related: https://github.com/cerebris/jsonapi-resources/issues/1465
@takaokouji takaokouji merged commit 17c0160 into master Jan 21, 2026
60 checks passed
@takaokouji takaokouji deleted the fix/rails72-activesupport-deprecation-1465 branch January 21, 2026 12:27
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.

NoMethodError: private method `warn' called for class ActiveSupport::Deprecation

1 participant