-
Notifications
You must be signed in to change notification settings - Fork 53
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
Drop Rails 4.2 support #108
Merged
Merged
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
Pull up a chair, and join me on this very fun walk-through of why, as of release 0.6.0, this gem doesn't actually support Rails 4.2 anymore and probably shouldn't. In #67, Rails 5+ support was added in the form of ditching our own dirty attribute logic and instead utilizing the fancy new Attributes API, which was officially introduced in Rails 5 but present (sorta) in Rails 4.2 as well. This very obviously cut off support of vault-rails for Rails 4.1, which doesn't have this API at all. Tests passed for Rails 4.2, so it looked good. However, the Attributes API in Rails 4.2 is actually totally private API - it's no more than a refactoring in anticipation of the real API in 5, and some of the API was accidentally exposed in documentation anyway in the 4.2 release. The whole point of the Attributes API is to provide a separation between ActiveModel attributes and the real database columns behind them (if any!), allowing you to flexibly cast types when putting and retrieving data from the database. However, in Rails 4.2 the API is simply a refactoring and the separation there doesn't exist: attributes are one-to-one with database columns. When vault-rails began to use the Attributes API in 0.6.0, a subtle behavior change occurred (for all versions of Rails): a `vault_attribute` is now registered as a real model attribute. This change is fine...in Rails 5+. In modern versions, ActiveRecord is smart enough to know that this defined attribute is _not_ backed by a database column, and is omitted from things that expect a column to exist. In Rails 4.2, it's not. The newly discovered attribute is expected to be backed by a database column, and things depend heavily on this expectation. The case that led me down finding this issue are complex queries utilizing joins and where conditions, which generate aliases through intermediate tables, e.g.: ``` SELECT "dogs"."id" AS t0_r0, "dogs"."owner_id" AS t0_r1, ........ ``` These queries are generated with a model's columns in mind, so you will now get an error with 0.6.0 and Rails 4.2 (where current_thought is a vault_attribute): ``` ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column dogs.current_thought does not exist LINE 1: ...AS t3_r38, "dogs"."current_thought" AS t3_r39, "dogs"."u... ``` Conclusion: As Rails 4.2 is long EOL'd anyway and we do *not* wish to maintain the old implementation alongside using the Attributes API, it makes sense to consider 0.6.x as supporting only Rails 5+. 0.5.0 will be the last known compatible version with Rails =< 4.2. This commit sets up dropping Rails 4.2 by demonstrating at this point that tests will fail with Rails 4.2 and pass with Rails 5+
This was only included because Rails 4.2 doesn't support Bundler 2. With Rails 4.2 support dropped, we don't need to do this anymore.
radditude
approved these changes
Sep 17, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Onwards and upwards!
Valarissa
approved these changes
Sep 17, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double approved~!
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.
Description
These changes:
In #67, Rails 5+ support was added in the form of ditching our own dirty attribute logic and instead utilizing the fancy new Attributes API, which was officially introduced in Rails 5 but present (sorta) in Rails 4.2 as well. This very obviously cut off support of vault-rails for Rails 4.1, which doesn't have this API at all. Tests passed for Rails 4.2, so it looked good.
However, the Attributes API in Rails 4.2 is actually totally private API - it's no more than a refactoring in anticipation of the real API in 5, and some of the API was accidentally exposed in documentation anyway in the 4.2 release.
The whole point of the Attributes API is to provide a separation between ActiveModel attributes and the real database columns behind them (if any!), allowing you to flexibly cast types when putting and retrieving data from the database. However, in Rails 4.2 the API is simply a refactoring and the separation there doesn't exist: attributes are one-to-one with database columns.
When vault-rails began to use the Attributes API in 0.6.0, a subtle behavior change occurred (for all versions of Rails): a
vault_attribute
is now registered as a real model attribute.This change is fine...in Rails 5+. In modern versions, ActiveRecord is smart enough to know that this defined attribute is not backed by a database column, and is omitted from things that expect a column to exist.
In Rails 4.2, it's not. The newly discovered attribute is expected to be backed by a database column, and things depend heavily on this expectation. This is evident via complex queries utilizing joins and where conditions, which generate aliases through intermediate tables, e.g.:
These queries are generated with a model's columns in mind, so you will now get an error with 0.6.0 and Rails 4.2 (where current_thought is a vault_attribute):
Conclusion: As Rails 4.2 is long EOL'd anyway and we do not wish to maintain the old implementation alongside using the Attributes API for that single old Rails version, I propose 0.6.x as supporting only Rails 5+, and 0.5.0 will be the last known compatible version with Rails =< 4.2.