Every time I execute my tests, I get these deprecation warnings:
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /Users/johnvanarkelen/Documents/Web development/rails/test-eagle/config/environment.rb:5)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /Users/johnvanarkelen/Documents/Web development/rails/test-eagle/config/environment.rb:5)
DEPRECATION WARNING: after_filter is deprecated and will be removed in Rails 5.1. Use after_action instead. (called from <top (required)> at /Users/johnvanarkelen/Documents/Web development/rails/test-eagle/config/environment.rb:5)
When I check line 5 of config/environment.rb
, there is this code:
Rails.application.initialize!
When I search my repo for after_action
, after_filter
or alias_method_chain
, it is not found. What can I do to get rid of these warnings?
To fix all deprecation warnings, follow the below steps: Replace update() with updateOne() , updateMany() , or replaceOne() Replace remove() with deleteOne() or deleteMany() . Replace count() with countDocuments() , unless you want to count how many documents are in the whole collection (no filter).
Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.
To warn about deprecation, you need to set Python's builtin DeprecationWarning as category. To let the warning refer to the caller, so you know exactly where you use deprecated code, you have to set stacklevel=2 .
If the deprecations are coming mostly from Rails, it may be time to disable the messages and save yourself from messy terminal output. The TL;DR is that you need to use RUBYOPT='-W:no-deprecated -W:no-experimental' to disable the deprecations. This will also disable experimental feature warnings as well.
I ran into alias_method_chain is deprecated ... from <top (required)> at /path/to/your/environment.rb
in a recent rails 5 upgrade. This typically points to usage in a gem required during the initialize!
call on your Rails application or a Bundler.require
if you are manually requiring your dependencies (which I happened to be).
It's probably better expressed as:
One of the random Gems you depend on did something I didn't like while Rails was initializing. Have fun finding it!
These are the loose steps I followed to sort out these unknown errors:
bundle show rails
or $GEM_PATH
to figure out where the gems for your bundle currently live (do note that this may be different for gems from different sources, e.g. git dependencies are stored differently than those from rubygems)grep
, ripgrip
ag
) to search for the deprecated method name e.g. rg "alias_method_chain" <gem path>
In my case, the deprecation warning for alias_method_chain
was in an outdated version of Kaminari. I updated my Gemfile to allow for a more recent version and then ran bundle update kaminari
to sort it.
Ignoring these warnings is a very bad idea; it's easy to let little things like this slip into your application if they have no immediate impact. That leads to normalizing the behavior of ignoring warnings or errors; that means more bugs and inconsistency in your application and a guaranteed bad time when you try to upgrade to a version of rails that removes the deprecated behavior. If you or your team establishes a standard of finding and fixing these errors immediately it's easy to spot and resolve real problems when they come up. Your future self will thank you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With