-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
ActiveSupport::Deprecation does not fallback to configured disallowed_behavior #44553
Comments
As a work-around, I am doing this in an initializer. ActiveSupport::Deprecations[:raise] = ->(...) { ... } |
|
|
@rafaelfranca I understand the mechanics of why it didn't work as I expected, but I feel like either this behavior is a bug, or the documentation could be improved. If the behavior is not open to discussion, the documentation for #deprecate_methods could be improved. This is where I got the idea to pass a custom deprecator, and it doesn't mention that this deprecator will not pick up any config from config.active_support.disallowed_deprecation. I'd still prefer to call this a bug, but if not: would a PR for that documentation change be more likely to be accepted? |
This is not a code bug, but it is a documentation bug. A PR to update the documentation makes sense. |
Ok, I tried updating the documentation, and that clarified what is surprising-enough-to-be-a-bug-IMO about this behavior: the global configuration of So one can't simply write something like this:
but instead must clarify which global settings will affect the custom deprecator, and which won't. Consider this (accurate) documentation:
It might not be a bug, but it sure feels wrong to require such complex explanations to avoid shooting yourself in the foot. Or maybe it's better to say that a custom deprecator using the global |
@rafaelfranca any chance this could be re-opened in light of the above? (It's been a few days and I'm not sure if you've seen my last comment). |
I agree that's pretty surprising. Just as a guess, do you think the issue is the use of Given the inconsistency here I'm going to reopen so we can investigate more. |
I think the first issue is deciding what the intended behavior here is, custom deprecators should either use or not use shared global config in a consistent way and right now they don't. @cpruitt seems to be the original author of this feature from #37940, maybe he can shed some light on how it should work? If custom deprecators are intended to be isolated and not use global config, then line 27 here is the culprit: rails/activesupport/lib/active_support/deprecation/disallowed.rb Lines 26 to 38 in a2217ae
Just changing that to use If custom deprecators should use the global config, then I'd say this lazy reader needs to be modified: rails/activesupport/lib/active_support/deprecation/behaviors.rb Lines 71 to 73 in f95c0b7
If an Personally I prefer the latter, since it was the behaviour I expected in the first place 😉 but I'm happy to contribute either solution. |
The latter seems correct to me also (but I'm not on core so don't take my word on it). If it's not too much effort it may be easier to discuss over a PR. |
Going to close this as well per #44772 (comment) |
Steps to reproduce
Expected behavior
I expect the custom
disallowed_behavior
to be called by#deprecation_warning
.Actual behavior
The gem-default behaviour (
:raise
) is called instead.System configuration
Rails version:
6.1.4.4 (but this problem affects all versions of Rails from 6.1 onwards)
Ruby version:
Ruby 3.1 (but this problem also occurs in earlier Ruby versions).
More information
I think this could be fixed by prepending a fallback to
ActiveSupport::Deprecation.disallowed_behavior
here:rails/activesupport/lib/active_support/deprecation/behaviors.rb
Lines 71 to 73 in 87d4d0f
However, because this class is using a singleton and InstanceDelegator the method might need two definitions, one on the class-level (that falls back to DEFAULT_BEHAVIORS) and one on the instance level (that falls back to the class-level behavior).
The text was updated successfully, but these errors were encountered: