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

Rails 5.0.7.2, Deprecation WARNING #403

Closed
ericproulx opened this issue Jun 3, 2020 · 9 comments
Closed

Rails 5.0.7.2, Deprecation WARNING #403

ericproulx opened this issue Jun 3, 2020 · 9 comments

Comments

@ericproulx
Copy link

Hello,

When running under Rails 5.0.7.2, we have a lot deprecations warning.

DEPRECATION WARNING: Passing a column to `quote` has been deprecated. It is only used for type casting, which should be handled elsewhere. See https://github.com/rails/arel/commit/6160bfbda1d1781c3b08a33ec4955f170e95be11 for more information. (called from update_most_recents at /Users/eproulx/code/statesman/lib/statesman/adapters/active_record.rb:144)
Arel performing automatic type casting is deprecated, and will be removed in Arel 8.0. If you are seeing this, it is because you are manually passing a value to an Arel predicate, and the `Arel::Table` object was constructed manually. The easiest way to remove this warning is to use an `Arel::Table` object returned from calling `arel_table` on an ActiveRecord::Base subclass.

If you're certain the value is already of the right type, change `attribute.eq(value)` to `attribute.eq(Arel::Nodes::Quoted.new(value))` (you will be able to remove that in Arel 8.0, it is only required to silence this deprecation warning).

You can also silence this warning globally by setting `$arel_silence_type_casting_deprecation` to `true`. (Do NOT do this if you are a library author)

If you are passing user input to a predicate, you must either give an appropriate type caster object to the `Arel::Table`, or manually cast the value before passing it to Arel.

Any ideas how to fix it ?

@lucascaton
Copy link

lucascaton commented Dec 14, 2020

Same with Rails 6.1 but for type_cast:

DEPRECATION WARNING: Passing a column to `type_cast` is deprecated and will be removed in Rails 6.2.

Rails' deprecation PR is this one: https://github.com/rails/rails/pull/39489/files

@lucascaton
Copy link

I just made the following change in the lib/statesman/adapters/active_record.rb file:

   def db_true
-    value = ::ActiveRecord::Base.connection.type_cast(
-      true,
-      transition_class.columns_hash["most_recent"],
-    )
-    ::ActiveRecord::Base.connection.quote(value)
+    true
   end

   def db_false
-    value = ::ActiveRecord::Base.connection.type_cast(
-      false,
-      transition_class.columns_hash["most_recent"],
-    )
-    ::ActiveRecord::Base.connection.quote(value)
+    false
   end

Although the specs still pass, I think this code is important as it was fixing this issue on MySQL, so I'm not sure what's the risks of removing it. There's likely a better solution 🙂

cc/ @thom-oman

@lucascaton
Copy link

Hi again, @thom-oman!
Is there anything I can do to help to fix this?

@thom-oman
Copy link
Contributor

Hi @lucascaton, sorry for the delayed reply. I just made this PR and we'll see how the tests do, as you point out it's MySQL that has caused issues with this in the past. My understanding of Arel isn't great but we'll see what the MySQL specs on that branch are saying

@thom-oman
Copy link
Contributor

OK they've failed, will try give this a look later today and get all the tests passing.

@lucascaton
Copy link

Hi @thom-oman, happy new year!

Have you had a chance to look at this? Is there anything I can do to help?

Thanks!

@thom-oman
Copy link
Contributor

Hey @lucascaton happy new year!

I'm just waiting on #421 being approved, will poke someone today to have a look! May also give it a sanity check in our monolith, though the Statesman specs should be enough.

@thom-oman
Copy link
Contributor

hey @lucascaton this been fixed in version 8! Let us know if there are any problems! :)

@lucascaton
Copy link

Thanks a lot, @thom-oman! 😃

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

No branches or pull requests

3 participants