Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add disallow_deprecation_warnings:rails #16

Closed

Conversation

george-ma
Copy link

@george-ma george-ma commented Apr 11, 2023

What are you trying to accomplish?

This work is a follow up of deprecation work handling the new Rails.application.deprecation for our Rails Upgrade script. We discussed that it would be nice to have a way to only configure the deprecations from Rails within an application as its those (Rails) deprecations that would need to be actioned on during a Rails upgrade.

Example of this working with the following test:

### In `test.rb`
config.active_support.disallowed_deprecation = :raise
config.active_support.disallowed_deprecation_warnings = :rails

### test/models/rails_deprecation_test.rb
# frozen_string_literal: true

require "test_helper"

class RailsDeprecationTest < ActiveSupport::TestCase
  test "deprecation warning from Rails" do
    ActionController::Parameters.new == {}
  end

  test "deprecation warning from a gem unrelated to Rails" do
    Rails.application.deprecators[:some_gem].warn("this is deprecated")
  end
end

1 deprecation from Rails, 1 deprecation defined in the sandbox itself- notice how only the deprecation from rails is "raised" as an error.
image

Work remaining:

  • Edit the docs guides/source/configuring.md; specifically, the config.active_support_disallowed_deprecation_warnings section to include mention of :all and :rails

What should reviewers focus on?

Before you deploy

@george-ma george-ma self-assigned this Apr 11, 2023
Co-authored-by: Étienne Barrié <etienne.barrie@shopify.com>
@george-ma george-ma force-pushed the gm/add-disallowed_deprecation_warnings-rails-flag branch from 8f69f35 to 95750f2 Compare April 17, 2023 16:32
Copy link

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this would be a nice feature! 😃

I like that the implementation is compact, but from an architectural standpoint, it feels a little odd to handle this from inside the deprecator. What I mean is, the way I would accomplish this without any special API would be something like:

Rails.application.deprecators.each do |deprecator|
  deprecator.disallowed_warnings = :all if deprecator.gem_name == "Rails"
end

To bridge the gap between that and config.active_support.disallowed_deprecation_warnings = :rails, perhaps we could introduce a Deprecators#disallow_warnings_from method:

# Could also accept a pattern (e.g. `/rails/i`) or multiple args
Rails.application.deprecators.disallow_warnings_from("Rails")

Then we could potentially add a config.active_support.disallow_warnings_from config setting. Though there might be a better / more consistent name.

Thoughts?

@jonathanhefner
Copy link

jonathanhefner commented Apr 18, 2023

perhaps we could introduce a Deprecators#disallow_warnings_from method

Or another possibility would be to add a Deprecators#disallow_warnings method with a :from or :gem option:

# Could also accept a pattern (e.g. `/rails/i`)
Rails.application.deprecators.disallow_warnings(gem: "Rails")

Afterward, we could add a matching option to #silence, e.g.:

Rails.application.deprecators.silence(gem: "Rails") do 
  # ...
end

@george-ma
Copy link
Author

👋🏻 appreciate the fast feedback! Fair point about the architectural awkwardness, I like the second option and will explore it asap!

@etiennebarrie
Copy link
Member

the way I would accomplish this without any special API would be something like

Oh yeah that would totally work and require no additional API. Given rails#46550 we should be able to do that in config/environments/production.rb and have all the Rails deprecators ready to be configured.

@george-ma
Copy link
Author

Will close for now as we will go with that no-api approach. Will revisit in the future if there is a need for other gems to be deprecated!

@george-ma george-ma closed this Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants