Deprecate using #quoted_id in quoting / type casting#27962
Deprecate using #quoted_id in quoting / type casting#27962rafaelfranca merged 3 commits intorails:masterfrom
#quoted_id in quoting / type casting#27962Conversation
b1a6543 to
8963225
Compare
There was a problem hiding this comment.
Is this necessary here? quoted_id was not being called here.
There was a problem hiding this comment.
If value is an AR::Base object, using value.id has potentially a bug.
If id: :datetime, precision: 3, typed cast value should be 2017-02-14 12:34:56.789000 by quoted_date, not 2017-02-14 12:34:56 +0000.
There was a problem hiding this comment.
If there is a potential bug in the current code we should add a test to it and fix before changing the behavior. Care to add the test?
There was a problem hiding this comment.
We don't need to deprecate here, it is only being used to make sure it is a AR::Base object.
There was a problem hiding this comment.
Originally using only value.id (skipping cast_type.serialize and _type_cast) has potentially a bug.
Do we keep the return value.id without deprecating?
There was a problem hiding this comment.
I understand the problem but in this case here quoted_id was never called and the deprecation message say it was. If using value.id is a bug we should just fix the bug and remove the deprecation.
8963225 to
2992f25
Compare
There was a problem hiding this comment.
I added the test that type casting serialization and removed deprecation message.
d27cec3 to
a103508
Compare
Originally `quoted_id` was used in legacy quoting mechanism. Now we use type casting mechanism for that. Let's deprecate `quoted_id`.
a103508 to
d155278
Compare
|
Thanks for this change. The |
Fixes rsim#1206 rails/rails#27962 moves `TypeCastingTest` from sqlite3 specific one to generic then some tests are failing. because `type_cast` and `quote` method both call `quoted_date` for `Date` and `Time` class objects in abstract adapter but Oracle enhanced adapter does not, using its own implementation. This pull request lets generic `Date` and `Type` objects handled by abstract adapter implementation. For non generic data types including timezone `ActiveRecord::OracleEnhanced::Type::TimestampTz` type has been created and `TimestampTz` type is handled as it used to. Oracle enhanced adpater now relies on `Time::DATE_FORMATS` defined in ActiveSupport by this change. Therefore changing `NLS_DATE_FORMAT` and `NLS_TIMESTAMP_FORMAT` are not working and will not be supported.
Fixes rsim#1206 rails/rails#27962 moves `TypeCastingTest` from sqlite3 specific one to generic then some tests are failing because `type_cast` and `quote` method both call `quoted_date` for `Date` and `Time` class objects in abstract adapter but Oracle enhanced adapter does not, using its own implementation. This pull request lets generic `Date` and `Type` objects handled by abstract adapter implementation. For non-generic data types including timezone `ActiveRecord::OracleEnhanced::Type::TimestampTz` type has been created and `TimestampTz` type is handled as it used to. Oracle enhanced adapter now relies on `Time::DATE_FORMATS` defined in ActiveSupport by this change. Therefore changing `NLS_DATE_FORMAT` and `NLS_TIMESTAMP_FORMAT` are not working and will not be supported.
Fixes rsim#1206 rails/rails#27962 moves `TypeCastingTest` from sqlite3 specific one to generic then some tests are failing because `type_cast` and `quote` method both call `quoted_date` for `Date` and `Time` class objects in abstract adapter but Oracle enhanced adapter does not, using its own implementation. This pull request lets generic `Date` and `Type` objects handled by abstract adapter implementation. For non-generic data types including timezone `ActiveRecord::OracleEnhanced::Type::TimestampTz` type has been created and `TimestampTz` type is handled as it used to. Oracle enhanced adapter now relies on `Time::DATE_FORMATS` defined in ActiveSupport by this change. Therefore changing `NLS_DATE_FORMAT` and `NLS_TIMESTAMP_FORMAT` are not working and will not be supported.
|
not very helpful error message ... would be great to point out the source_location ... just ran into this without having the slightest hint on where the quote_id is coming from ... had to open up the gem to debug ... turns out to be active_hash ... but when I remove the quote_id support then it just blows up :/ ... so had to go through all places that use the fake AR and change them to call |
|
Sounds like you should file a bug with ActiveHash if the problem is there... |
|
|
|
There is no replacement for that method. If you need to quote you id differently you need to define a different type for that column. |
|
The replacement appears to be defining a |
|
No, that is not the replacement, the |
|
Sorry, then I misunderstood the intent here. My use case for Overly simplified example: class CustomClass
def initialize( val )
@val = val
end
# for Rails >= 5.2
def value_for_database
@val.to_i
end
# for Rails < 5.2
alias_method :quoted_id, :value_for_database
end
obj = CustomClass.new('2')
SomeModel.where( some_integer_column: obj )Implementing |
@rafaelfranca Can you point in a direction for looking into definining a different type for a column? I see some AR addons are 'stuck' on 5.1 due to the quoted_id change. |
|
@rafaelfranca Thanks! |
Since Rails 4.2, Rails allows for defining custom data types. This feature replaces old hacks, which have been finally removed in Rails 5.2. For more information, see RDoc introduced in this commit, and this comment: rails/rails#27962 (comment)
Since Rails 4.2, Rails allows for defining custom data types. This feature replaces old hacks, which have been finally removed in Rails 5.2. For more information, see RDoc introduced in this commit, and this comment: rails/rails#27962 (comment)
Since Rails 4.2, Rails allows for defining custom data types. This feature replaces old hacks, which have been finally removed in Rails 5.2. For more information, see RDoc introduced in this commit, and this comment: rails/rails#27962 (comment)
…ctly Follow up to rails#27962. rails#27962 only deprecated `quoted_id`, but still conservatively allowed passing an Active Record object. Since the quoting methods on a `connection` are low-level API and querying API does not rely on that ability, so people should pass casted value instead of an Active Record object if using the quoting methods directly.
Originally
quoted_idwas used in legacy quoting mechanism. Now we usetype casting mechanism for that. Let's deprecate
quoted_id.