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

Replace 'type_cast_from_column' to support Rails 6.1 #68

Merged
merged 1 commit into from
Feb 5, 2021

Conversation

zjohl
Copy link
Contributor

@zjohl zjohl commented Jan 20, 2021

Passing a column to the active_record method type_cast is deprecated and will be removed in Rails 6.2. The type_cast_from_column method was also removed as part of Rails 6.1 in this PR. In the short term we can manually call lookup_cast_type_from_column and serialize our values with the returned type.

This resolves errors that look like the following, which occur when using bulk_insert and active_record 6.1.X, such as #67:

undefined method `type_cast_from_column'

@zjohl
Copy link
Contributor Author

zjohl commented Jan 25, 2021

@mberlanda Does this seem like a reasonable change? I'm trying to upgrade a project to Rails 6.1 and it would be really helpful if we could release 1.8.2 with this change

@krisleech
Copy link

This patch works great on Rails 6.1.1.

Copy link
Collaborator

@mberlanda mberlanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the fix and sorry for the delay in the review. How did you test that this change is backward compatible? A part from that it looks good to me

value = @connection.type_cast_from_column(column, value) if column
if column
type = @connection.lookup_cast_type_from_column(column)
value = type.serialize(value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we confirm that this addition is backward compatible with Rails versions between 5 and 6.1?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run some tests locally and it seems to work.

value = @connection.type_cast_from_column(column, value) if column
if column
type = @connection.lookup_cast_type_from_column(column)
value = type.serialize(value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run some tests locally and it seems to work.

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

Successfully merging this pull request may close these issues.

None yet

3 participants