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
Deprecate passing a column to type_cast
#39106
Merged
kamipo
merged 1 commit into
rails:master
from
kamipo:deprecate_passing_column_to_type_cast
May 2, 2020
Merged
Deprecate passing a column to type_cast
#39106
kamipo
merged 1 commit into
rails:master
from
kamipo:deprecate_passing_column_to_type_cast
May 2, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The type information for type casting is entirely separated to type object, so if anyone does passing a column to `type_cast` in Rails 6, they are likely doing something wrong. See the comment for more details: https://github.com/rails/rails/blob/28d815b89487ce4001a3f6f0ab684e6f9c017ed0/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb#L33-L42 This also deprecates passing legacy binds (an array of `[column, value]` which is 4.2 style format) to query methods on connection. That legacy format was kept for backward compatibility, instead of that, I've supported casted binds format (an array of casted values), it is easier to construct binds than existing two binds format.
kamipo
force-pushed
the
deprecate_passing_column_to_type_cast
branch
from
May 1, 2020 22:18
aeafd59
to
92360e9
Compare
koic
added a commit
to koic/oracle-enhanced
that referenced
this pull request
May 2, 2020
koic
added a commit
to koic/oracle-enhanced
that referenced
this pull request
May 2, 2020
Follow up to rails/rails#39106.
huacnlee
added a commit
to huacnlee/bulk_insert
that referenced
this pull request
Sep 28, 2020
In Rails 6.1 type_cast_from_column API has been removed: rails/rails#39106 lookup_cast_type_from_column was exists in Rails 5.0
kamipo
added a commit
to kamipo/rails
that referenced
this pull request
Jan 16, 2021
Related issue rails#41133. In rails#39106, I've allowed binds of casted values as an alternative of the legacy binds (an array of `[column || nil, value]`) to deprecate and remove the legacy binds support in a future version of Rails. At that time, I've respected the existing logging format for binds. i.e. ```ruby # legacy binds conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [[nil, 1], [nil, 2]]) # (0.1ms) SELECT * FROM events WHERE id IN (?, ?) [[nil, 1], [nil, 2]] # casted binds conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [1, 2]) # (0.1ms) SELECT * FROM events WHERE id IN (?, ?) [[nil, 1], [nil, 2]] ``` To improve the performance of generating IN clause, 72fd0ba avoids `build_bind_attribute` for each values, so now binds has become casted values. ```ruby conn.select_all(Event.where(id: [1, 2])) # (0.1ms) SELECT * FROM events WHERE id IN (?, ?) [[nil, 1], [nil, 2]] ``` Regardless of whether 72fd0ba avoids `build_bind_attribute` or not, the logging format for the binds of casted values is odd (at least not pretty to me). I'd like to concise the logging format to just use casted values. ```ruby conn.select_all("SELECT * FROM events WHERE id IN (?, ?)", nil, [1, 2]) # (0.1ms) SELECT * FROM events WHERE id IN (?, ?) [1, 2] conn.select_all(Event.where(id: [1, 2])) # (0.1ms) SELECT * FROM events WHERE id IN (?, ?) [1, 2] ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The type information for type casting is entirely separated to type
object, so if anyone does passing a column to
type_cast
in Rails 6,they are likely doing something wrong. See the comment for more details:
rails/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
Lines 33 to 42 in 28d815b
This also deprecates passing legacy binds (an array of
[column, value]
which is 4.2 style format) to query methods on connection. That legacy
format was kept for backward compatibility, instead of that, I've
supported casted binds format (an array of casted values), it is easier
to construct binds than existing two binds format.