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

THREESCALE-10880: Bump rails from 6.0.6.1 to 6.1.7.7 #3705

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

dependabot[bot]
Copy link
Contributor

@dependabot dependabot bot commented on behalf of github Feb 28, 2024

Completed tasks:

The JIRA for this Rails 6.1 upgrade: https://issues.redhat.com/browse/THREESCALE-10880


*To fix in Oracle:

rspec './spec/acceptance/api/application_spec.rb[1:1:1:1:1]' # Cinstance application json format GET /admin/api/applications.:format List Application
rspec './spec/acceptance/api/application_spec.rb[1:1:2:1:1]' # Cinstance application xml format GET /admin/api/applications.:format List Application

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 (aliased RAW_RNUM_). So, the query actually tries to find something like AND "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.

6.1.7.7

Active Support

  • No changes.

Active Model

  • No changes.

Active Record

  • No changes.

Action View

  • No changes.

Action Pack

  • No changes.

Active Job

  • No changes.

Action Mailer

  • No changes.

Action Cable

  • No changes.

... (truncated)

Commits
  • ac87f58 Preparing for 6.1.7.7 release
  • fc2f1b8 update changelog
  • 78fe149 Merge pull request #48869 from brunoprietog/disable-session-active-storage-pr...
  • 56bcc0a Preparing for 6.1.7.6 release
  • 1f03e9d Bumping version for new release
  • 3a1b615 Preparing for 6.1.7.5 release
  • c2af578 bumping version / changelog
  • c85cc66 Use a temporary file for storing unencrypted files while editing
  • 7d949d7 Preparing for 6.1.7.4 release
  • 11d5de1 update changelog
  • Additional commits viewable in compare view

Dependabot compatibility score

You 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.

Note
Automatic rebases have been disabled on this pull request as it has been open for over 30 days.

@dependabot dependabot bot added dependencies Pull requests that update a dependency file ruby Pull requests that update Ruby code labels Feb 28, 2024
@dependabot dependabot bot force-pushed the dependabot/bundler/rails-6.1.7.7 branch 3 times, most recently from e3e230c to 27d3cdd Compare March 6, 2024 13:34
@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch from 6cb2c9c to 71f725c Compare March 8, 2024 23:09
@mayorova mayorova changed the title Bump rails from 6.0.6.1 to 6.1.7.7 THREESCALE-10880: Bump rails from 6.0.6.1 to 6.1.7.7 Mar 8, 2024
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -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)
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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.

Copy link
Contributor

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?

# 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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@mayorova mayorova Apr 19, 2024

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)
Copy link
Contributor

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') }
Copy link
Contributor

Choose a reason for hiding this comment

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

This changed from File.join(self.class.fixture_path, path) to Pathname.new(self.class.fixture_path).join(path) and the latter treats /wide.jpg as an absolute path (rightfully, IMO).

image

Gemfile Outdated
@@ -265,4 +265,4 @@ end

gem 'kubeclient'

gem 'pg', '~> 0.21.0'
gem 'pg', '~> 1.3'
Copy link
Contributor

@mayorova mayorova Mar 13, 2024

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.

Copy link
Contributor

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

Copy link
Contributor

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).

@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch from d1111f6 to 6f16f2a Compare March 13, 2024 15:20
@@ -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)
Copy link
Contributor

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:

Screenshot from 2024-03-14 13-40-27

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 😬

Copy link
Contributor

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

@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch 2 times, most recently from c80f107 to 55320cd Compare March 14, 2024 14:35
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
Copy link
Contributor

@mayorova mayorova Mar 15, 2024

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.

@@ -24,17 +24,14 @@ def save!(*)
protected

def merge_errors
definitions = property_definitions.values
definitions.each do |definition|
schema.each do |value|
Copy link
Contributor

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:

  1. I am not sure if the behavior is 100% equivalent
  2. 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
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

@jlledom jlledom May 14, 2024

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.

@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch from 1410363 to 96bab09 Compare March 15, 2024 14:21
akostadinov
akostadinov previously approved these changes May 13, 2024
Copy link
Contributor

@akostadinov akostadinov left a 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
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
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/lib/event_store/event.rb Show resolved Hide resolved
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)} ) }
Copy link
Contributor

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.

app/models/contract.rb Outdated Show resolved Hide resolved
test/unit/event_store/event_test.rb Outdated Show resolved Hide resolved
test/unit/event_store/event_test.rb Outdated Show resolved Hide resolved
test/unit/event_store/event_test.rb Outdated Show resolved Hide resolved
@mayorova
Copy link
Contributor

One comment suggestion, other than that ready to go IMO!

f1e2ad9 @akostadinov

akostadinov
akostadinov previously approved these changes May 14, 2024
# 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)} ) }
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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 😬

@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch 2 times, most recently from 1425637 to e51c72d Compare May 15, 2024 08:51
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)
@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch from 3f442b5 to e62185e Compare May 15, 2024 10:10
@mayorova mayorova force-pushed the dependabot/bundler/rails-6.1.7.7 branch from 568945c to 6485c37 Compare May 15, 2024 12:10
Copy link
Contributor

@jlledom jlledom left a comment

Choose a reason for hiding this comment

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

Good job! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file ruby Pull requests that update Ruby code
Projects
None yet
3 participants