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

Support new @raw_connection ivar name #309

Merged
merged 1 commit into from
Mar 1, 2022
Merged

Conversation

nvasilevski
Copy link
Contributor

Rails change - rails/rails@d86fd64

Next version of Rails will use a different name for the @connection variable and semian needs to support this
Since we can't rely on any version check at this moment so I used instance_variable_defined to determine which variable to use

Is there a better way to support both ivars?

@nvasilevski nvasilevski requested a review from a team February 28, 2022 18:58
@@ -2,6 +2,8 @@

class ActiveRecord::ConnectionAdapters::AbstractAdapter
def semian_resource
@connection.semian_resource
# support for https://github.com/rails/rails/commit/d86fd6415c0dfce6fadb77e74696cf728e5eb76b
connection = instance_variable_defined?("@raw_connection") ? @raw_connection : @connection

Choose a reason for hiding this comment

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

I don't have an opinion, in fact I'm simply curious:

I wonder if explicitly using the Rails version to discriminate on the ivar has advantages? It certainly makes the intent more clear, in that it's for backwards compatibility. I suppose it's more fragile, though.

Curious what others think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like that question comes often and I haven't heard strong preference on this. I believe last time we were discussing something similar we agreed that using explicit Rails version branching more often used but no obvious advantage/disadvantage

Also curious about other opinions!

Copy link
Contributor

Choose a reason for hiding this comment

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

When it's not too complicated I prefer feature checking, especially when it's for yet unreleased versions, because I've seen changes like this be reverted in the past, so feature testing is more reliable.

@@ -2,6 +2,8 @@

class ActiveRecord::ConnectionAdapters::AbstractAdapter
def semian_resource
@connection.semian_resource
# support for https://github.com/rails/rails/commit/d86fd6415c0dfce6fadb77e74696cf728e5eb76b
connection = instance_variable_defined?("@raw_connection") ? @raw_connection : @connection
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
connection = instance_variable_defined?("@raw_connection") ? @raw_connection : @connection
connection = instance_variable_defined?(:@raw_connection) ? @raw_connection : @connection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense 👍 Changed

@nvasilevski
Copy link
Contributor Author

I may need to fix CI separately before merging this PR, I don't think failures are related to the change

@nvasilevski nvasilevski merged commit 470b635 into master Mar 1, 2022
@nvasilevski nvasilevski deleted the support-rails-edge branch March 1, 2022 15:07
@nvasilevski nvasilevski mentioned this pull request Mar 1, 2022
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.

4 participants