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

Avoid changing method visibility when deprecating a method #2449

Merged

Conversation

jordan-brough
Copy link
Contributor

ActiveSupport::Deprecation::MethodWrapper#deprecate_methods changes method
visibility to public. This seems unintentional and I will submit a PR to
Rails to see if that can be updated.

For the meanwhile, this update changes method visibility back to the original
visibility. It's a bit more convoluted than might be expected because
ActiveSupport uses Module.prepend to override the original method, so we can't
just write private :some_method because that only affects the original method,
whose visibility has not been changed.

If people think it's worth creating a helper for this let me know and I will do so.

ActiveSupport::Deprecation::MethodWrapper#deprecate_methods changes method
visibility to `public`.  This seems unintentional and I will submit a PR to
Rails to see if that can be updated.

For the meanwhile, this update changes method visibility back to the original
visibility. It's a bit more convoluted than might be expected because
ActiveSupport uses `Module.prepend` to override the original method, so we can't
just write `private :some_method` because that only affects the original method,
whose visibility has not been changed.
@jordan-brough
Copy link
Contributor Author

I've submitted a Rails PR here: rails/rails#31433 to fix this in ActiveSupport.

@gmacdougall
Copy link
Member

Thanks for finding this Jordan.

I prefer to leave this as is and update to a new rails version when this is fixed upstream.

@jordan-brough
Copy link
Contributor Author

@gmacdougall I think it's worth going ahead and fixing this. My fix was only merged into Rails master and Rails v5.2 is already in beta so I imagine it'll be a good while before that trickles back to Solidus. It's good to have correct method visibility for the apps using Solidus imo, even for deprecated methods.

@jhawthorn
Copy link
Contributor

jhawthorn commented Dec 20, 2017

Nice catch.

My fix was only merged into Rails master and Rails v5.2 is already in beta so I imagine it'll be a good while before that trickles back to Solidus

I think rails master is still tracking 5.2, so it shouldn't be too long.

Alternatively, we could use Spree::Deprecation.warn explicitly within the private method, which avoids the slight strangeness of instance_method(...).owner.send(:private, ...). I am 👍 with any of the 3 approaches.

@jordan-brough
Copy link
Contributor Author

jordan-brough commented Dec 20, 2017

we could use Spree::Deprecation.warn explicitly within the private method

Great point, I'll update with that 👍 (at least for the ones where the method is defined in a way that's friendly to that)

Simply calling `deprecate` created the `provider_class` method on the base class
(and all subclasses) but it did so in a way that would blow up with an error
like:

    NoMethodError: super: no superclass method `provider_class'

Defining the method also messed up the check on `respond_to? :provider_class`
in the `gateway_class` method.

Also, calling `deprecate` in the base class would not generate deprecation
warnings for any `provider_class` methods defined in subclasses.
@jordan-brough
Copy link
Contributor Author

@jhawthorn @gmacdougall I removed a broken deprecation no Spree::PaymentMethod#provider_class and updated the remaining ones to use Spree::Deprecation.warn. Look good?

@jordan-brough jordan-brough merged commit 1276ef0 into solidusio:master Jan 10, 2018
@jordan-brough jordan-brough deleted the fix-deprecated-method-visibility branch January 10, 2018 18:08
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.

None yet

3 participants