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
THREESCALE-10880: Bump rails from 6.0.6.1 to 6.1.7.7 #3705
base: master
Are you sure you want to change the base?
Conversation
e3e230c
to
27d3cdd
Compare
6cb2c9c
to
71f725c
Compare
@@ -104,7 +104,7 @@ def update_version | |||
|
|||
# Read the value | |||
version = config.connection.select_value(config.select(:version)).to_i | |||
write_attribute_without_type_cast :version, version | |||
write_attribute_without_type_cast 'version', version |
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.
This behavior seems to have been changed here: rails/rails@7834363#diff-f029f28568c577e87cb998285cfdc00c05df84e95e9c28eb115c148e528c2b44L46
@@ -9,8 +9,11 @@ def initialize(options) | |||
def validate_each(record, _attribute, value) | |||
return if !value || value.valid? || value.marked_for_destruction? | |||
options[:report].each do |alternate, attr| | |||
errors = value.errors.messages[alternate] | |||
record.errors[attr || alternate].concat(errors) if errors.present? | |||
errors = value.errors.where(alternate) |
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.
This block fixes a FrozenError (described here, and uses a new Error interface, see rails/rails#32313
config/application.rb
Outdated
@@ -240,7 +240,7 @@ def cache_store_config | |||
config.three_scale.cors.enabled = false | |||
config.three_scale.cors.merge!(try_config_for(:cors) || {}) | |||
|
|||
three_scale = config_for(:settings).symbolize_keys | |||
three_scale = config_for(:settings).deep_symbolize_keys |
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.
I don't quite get this one to be honest 🙃
I think some things broke because of this change: https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#rails-application-config-for-return-value-no-longer-supports-access-with-string-keys
However, it says that what stopped being supported is access with string keys, but what I observe is that the difference is that now the hash that is produced by config_for
on the contrary has string keys, and not symbols like it used to be. So, maybe I'm missing something...
But this specific change fixes several issues with the impersonation_admin
config.
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.
Is maybe related to this?
Lines 88 to 93 in d2fc12b
# The old config_for gem returns HashWithIndifferentAccess | |
# https://github.com/3scale/config_for/blob/master/lib/config_for/config.rb#L16 | |
def config_for(*args) | |
config = super | |
config.is_a?(Hash) ? config.with_indifferent_access : config | |
end |
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.
Yeah, but we are using the Rails config_for
, it's just the description of the change is not 100% aligned with the actual behavior. But to be honest, I already don't remember how it used to behave, and how it behaves now. If needed, I can recheck :)
But this works.
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.
Yeah, but we are using the Rails
config_for
If I place a breakpoint on our config_for
it stops many times, so we use it. Anyway, if it works, fine for me.
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.
@jlledom Yes yes, we DO use this method, what I meant is we then use Rails' (via super
) config_for
.
I've been looking into it, and indeed, the Rails' description is correct. Rails' config_for
now returns a config that is deep-symbolized already. But when we apply .with_indifferent_access
, and then .symbolize_keys
that was lost, and accessing the nested values by symbols didn't work: Rails.application.config.three_scale.impersonation_admin[:domain]
was nil.
Applying .deep_symbolize_keys
fixed this. But also, I think we transform the configs too much, and they are not consistent (deep_symbolize_keys
is applied for some, symbolize_keys
applied for others etc.).
So, I thought we could take this opportunity to align all, and to use the default format that Rails provides - ActiveSupport::OrderedOptions
with deep-symbolized keys.
We just need to make sure we use symbols throughout the app.
This is applied here: dc7bf1a
end | ||
|
||
def adapter | ||
adapter_method.match(/^(oracle|postgres|mysql).*/).to_a.last | ||
end | ||
|
||
def adapter_method | ||
ActiveSupport::StringInquirer.new(configuration_specification.adapter_method) | ||
@adapter_method ||= ActiveSupport::StringInquirer.new(database_config.adapter) |
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.
database_config.adapter_method
also exists, but it basically is a contatenation of _connection
to the adapter value:
https://github.com/rails/rails/blob/v6.1.7.7/activerecord/lib/active_record/database_configurations/database_config.rb#L27-L29
@@ -21,7 +21,7 @@ | |||
parameter :attachment, 'The Attachment' | |||
|
|||
let(:section_id) { resource.section_id } | |||
let(:attachment) { fixture_file_upload('/wide.jpg',' image/jpeg') } | |||
let(:attachment) { fixture_file_upload('wide.jpg',' image/jpeg') } |
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.
Gemfile
Outdated
@@ -265,4 +265,4 @@ end | |||
|
|||
gem 'kubeclient' | |||
|
|||
gem 'pg', '~> 0.21.0' | |||
gem 'pg', '~> 1.3' |
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.
It seems that in the latest Rails 6.1 the required version is ">= 1.3.0.rc1", but the error I was getting:
Gem::LoadError: can't activate pg (~> 1.1), already activated pg-0.21.0. Make sure all dependencies are added to Gemfile.
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.
such error I usually see when I forget to call bundle exec ...
but it's fine to get it updated either way
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.
Forgetting bundle exec
was not the case, but indeed there was something weird 😬
I sometimes get this error for the default gems (like json
).
d1111f6
to
6f16f2a
Compare
@@ -18,7 +18,7 @@ module Representer | |||
|
|||
test '#to_format PATCH' do | |||
@controller.formats = [:json] | |||
@controller.request = ActionDispatch::Request.new('REQUEST_METHOD' => 'PATCH') | |||
@controller.request = ActionDispatch::Request.new('REQUEST_METHOD' => 'PATCH', 'rack.input' => StringIO.new) |
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.
This one made me scratch my head quite a bit...
The error was:
Error:
ThreeScale::Api::ResponderTest#test_#to_format_PATCH:
RuntimeError: Missing rack.input
test/unit/three_scale/api/responder_test.rb:25:in `block in <class:ResponderTest>'
Debugging showed that it was caused by https://github.com/rack/rack/blob/v2.2.8.1/lib/rack/request.rb#L441-L442
And the reason why this called in the first place was this addition:
added here: rails/rails@5745a3c
By the way, rack.input
was later made optional in rack: rack/rack#2018
But this version is not released yet.
I think this really happens just because we are creating this fake request, and in real-life scenario this would not cause issues, so I think adding rack.input
to the env
in Request initializer should do the trick. But I don't understand this test enough to be sure 😬
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.
maybe put a comment that this can be removed after we have a rack version with rack/rack#2018
c80f107
to
55320cd
Compare
Gemfile
Outdated
@@ -124,7 +124,8 @@ gem 'rack-x_served_by', '~> 0.1.1' | |||
gem 'rack-cors' | |||
gem 'roar-rails' | |||
|
|||
gem 'reform', '~> 2.0.3', require: false | |||
gem 'reform', '~> 2.3.0', require: false | |||
gem 'reform-rails', '~> 0.2.2', require: false |
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.
This upgrade is extracted to #3725 and this PR will be rebased once it is merged.
app/lib/three_scale/reform.rb
Outdated
@@ -24,17 +24,14 @@ def save!(*) | |||
protected | |||
|
|||
def merge_errors | |||
definitions = property_definitions.values | |||
definitions.each do |definition| | |||
schema.each do |value| |
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.
I found this change pretty tricky, because I don't really understand the documentation of the reform
gem very well (not sure if it's mine, or the documentation's fault).
This seems to do the trick, although:
- I am not sure if the behavior is 100% equivalent
- The code says
The #errors method will be removed in Reform 3.0 core. def errors(*args)
https://github.com/trailblazer/reform/blob/v2.6.2/lib/reform/contract/validate.rb#L14
Also, there are just three forms, it seems, that use reform
,and honestly, I think it might be possible to get rid of it at some point and simplify the implementation.
I think for the current purposes this rework should be enough, but probably we can refactor/remove this later.
run Rails.application | ||
Rails.application.load_server |
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.
Not sure it's a good idea to add this... but this is the new default content of config.ru
:
rails/rails@868866c
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.
I think it's fine to have it. It won't make any difference unless we manually add servers anyway.
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.
Not sure what you mean by manually adding servers.
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.
@jlledom ☝️ ?
I don't know what this line does. It's just coming in the default templates now.
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.
@mayorova @akostadinov this line runs whatever blocks you added through Rails::Railtie.server
. Check https://api.rubyonrails.org/v6.1.7.7/classes/Rails/Railtie.html, at the section Run another program when the Rails server starts.
AFAIK we don't use this feature so there's no difference having this line or not.
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.
There might be gems that use, now or in the future?
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.
No idea, but it seems to me the best decision is to leave this line. If servers are added, this line is required; if no servers are added, this line does nothing. So it will work in all scenarios, and it's only executed once during startup, so it has no impact on performance.
1410363
to
96bab09
Compare
2aa1981
to
1ea06c6
Compare
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.
One comment suggestion, other than that ready to go IMO!
|
||
# Support for inversing belongs_to -> has_many Active Record associations. | ||
# Overriding Rails 6.1 default, because it causes various issues | ||
config.active_record.has_many_inversing = false |
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.
config.active_record.has_many_inversing = false | |
# likely need to keep it forever as we can't override it for individual use cases | |
# also the feature has outstanding bugs: rails/rails#47559 rails/rails#50258 | |
config.active_record.has_many_inversing = false |
app/models/cinstance.rb
Outdated
where{ plan_id.in( my{Plan.issued_by(service).select(:id)} ) } | ||
# NOTE: `reorder(nil)` resets the order set in the Plan's default scope, | ||
# because ORDER BY in subqueries fails in Oracle with 'ORA-00907: missing right parenthesis'. | ||
where { plan_id.in( my { Plan.issued_by(service).select(:id).reorder(nil)} ) } |
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.
If I understood this correctly, you want to remove the ordered default scope because that's not compatible with Oracle, is that right? in that case I think its a good idea to remove it.
|
# NOTE: `reorder(nil)` resets the order set in the Plan's default scope, | ||
# because ORDER BY in subqueries fails in Oracle with 'ORA-00907: missing right parenthesis'. | ||
where { plan_id.in( my { Plan.issued_by(service).select(:id).reorder(nil)} ) } | ||
where { plan_id.in( my { Plan.issued_by(service).select(:id)} ) } |
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.
I wouldn't remove the reorder(nil)
from these queries. IMO keep it. It is solid to stay. But also fine to remove if you really want.
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.
After removing the default scope I don't think it's needed. And if someone ever wants to add the default scope, or add some order in subqueries, the test should fail.
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.
I reverted the reorder(nil)
, but the spaces changes have left 😬
1425637
to
e51c72d
Compare
This is caused by the following change: https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#rails-application-config-for-return-value-no-longer-supports-access-with-string-keys Now all configs coming from YAML files are deep-symbolized by default
e51c72d
to
3f442b5
Compare
Rails 6.1 cuts out the `no-cache` value from the header, due to this normalization [1], see commit [2]. According to the docs [3] `no-store` is "stronger" than `no-cache`, which indeed makes `no-cache` redundant in presence of `no-store`, so I changed the headers we set in `ApplicationController#disable_client_cache`. [1] https://github.com/rails/rails/blob/v6.1.7.7/actionpack/lib/action_dispatch/http/cache.rb#L185-L222 [2] rails/rails@e06f7b3#diff-d77084e8407ab72b3068ae0268553de59c351ba520adc9c248e24e887b3fd5bf [3] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
Old Arel visitor was causing issues with ROWNUM, so we removed it. The new Arel visitor forms some queries that incude subqueries with ORDER BY, which throws an error in Oracle: ORA-00907: missing right parenthesis So, order has been removed from some scopes to avoid this issue.
This got broken in Rails 6.1, specifically for PostgreSQL, reported in rails/rails#41651 It was fixed by rails/rails@587522e but I believe that the fix in this commit will work both with or without the Rails fix, so we don't need to worry about it when we upgrade again (it's just that the .cast method will be called more times after all column types are back again in the `column_types` hash in Rails 7, which was the behavior until Rails 6.1)
3f442b5
to
e62185e
Compare
568945c
to
6485c37
Compare
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.
Good job! 🥳
Completed tasks:
load_defaults
to 6.1 atapplication.rb
The JIRA for this Rails 6.1 upgrade: https://issues.redhat.com/browse/THREESCALE-10880
*To fix in Oracle:
Result of the paginated query returns an empty array, when before pagination there were 2 items.
The reason of this seems to be caused by the following change:
rails/rails@2ad2425#diff-f35ba011d4738058fa067289f7585a0224ef8ab22efe7a7ecdb07c2fed6940eaR419-R420
The result of the previous query (which is supposed to be calculating the list of IDs) used to return
ActiveRecord::Result
, from which the primary key column was plucked. Now it returns an array of pairs, in which the first value is the ID, and the second (aka last) value is the rownum (aliasedRAW_RNUM_
). So, the query actually tries to find something likeAND "CINSTANCES"."ID" IN (1,2,3,4,5,6,7,8,9,10)
, which is WRONG (because it compares IDs with rownums).Bumps rails from 6.0.6.1 to 6.1.7.7.
Release notes
Sourced from rails's releases.
... (truncated)
Commits
ac87f58
Preparing for 6.1.7.7 releasefc2f1b8
update changelog78fe149
Merge pull request #48869 from brunoprietog/disable-session-active-storage-pr...56bcc0a
Preparing for 6.1.7.6 release1f03e9d
Bumping version for new release3a1b615
Preparing for 6.1.7.5 releasec2af578
bumping version / changelogc85cc66
Use a temporary file for storing unencrypted files while editing7d949d7
Preparing for 6.1.7.4 release11d5de1
update changelogYou can trigger a rebase of this PR by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot show <dependency name> ignore conditions
will show all of the ignore conditions of the specified dependency@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)You can disable automated security fix PRs for this repo from the Security Alerts page.