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

Do not update load_defaults version when running app:update #31951

Merged

Conversation

y-yagi
Copy link
Member

@y-yagi y-yagi commented Feb 10, 2018

Incompatible settings are included in the settings set by load_defaults.
So, I think that target version should be updated by a user when becomes available, and should not be updated with app:update.

FileUtils.cd(destination_root) do
config = "config/application.rb"
content = File.read(config)
File.write(config, content.gsub(/config\.load_defaults #{Rails::VERSION::STRING.to_f}/, "config.load_defaults 5.2"))
Copy link
Member

Choose a reason for hiding this comment

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

Let's use 5.1, so this test still applies when backported to 5.2

@@ -130,6 +130,9 @@ def config_when_updating
assets_config_exist = File.exist?("config/initializers/assets.rb")
csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")

load_defaults = File.read("config/application.rb").match(/config\.load_defaults (\d\.\d)/)
Copy link
Member

Choose a reason for hiding this comment

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

I think we also need a test that this matches the generated content (e.g., right now it would stop working for version 10.0, but no test would fail). Do you have any ideas how we could do that?

Copy link
Member

Choose a reason for hiding this comment

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

Two other thoughts on the regex:

  1. Start with /^\s*, to ignore commented lines.
  2. Technically, the argument is allowed to be a string (because 6.10.to_s and "6.10".to_s are very different)... but maybe that's not worth worrying about for now.

@@ -130,6 +130,9 @@ def config_when_updating
assets_config_exist = File.exist?("config/initializers/assets.rb")
csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")

load_defaults = File.read("config/application.rb").match(/config\.load_defaults (\d\.\d)/)
@config_target_version = load_defaults[1] if load_defaults
Copy link
Member

Choose a reason for hiding this comment

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

If there's no load_defaults in there, but we're upgrading... maybe this should be:

@config_target_version = load_defaults[1] || "5.0"

Copy link
Member

Choose a reason for hiding this comment

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

If there's no config.load_defaults line in the file, and we regenerate it with config.load_defaults 5.0, we've opted the app into a set of defaults that they weren't getting before - which is what we're trying to avoid here.

I think we should skip the load_defaults line in the template if we didn't find it in the current file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's a fair point. But since I would like to recommend using load_defaults, want to avoid skip.
So, I added version 4.2 which does not affect existing configs and used it there.

@matthewd What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I think omitting it for upgrades is fine... people should really be doing a stepwise upgrade anyway, so it will be rare for 5.2 to see an app that was never upgraded to 5.0 or 5.1. (That's also why I went for 5.0... it's not correct, but seemed less bother than making the whole line optional just for a corner case.)

Offering 4.2 seems more likely to be confusing, because it's not really true... IIRC we changed a number of the 'real'/baseline defaults in 5.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

My concern was belongs_to_required_by_default. It effects to the whole application.
But I fixed it to 5.0 in order to agree that 4.2 is confusing and that it seems to have responded somewhat already with the update from 5.0 to 5.1.
(I also do not agree much to make the whole line an option for that corner case)

@matthewd
Copy link
Member

The other option, instead of parsing the file, would be to remember the target_version inside load_defaults... I think the application is (or could be?) booted when we run the upgrade task. This does seem simpler, though. 👍

@y-yagi y-yagi force-pushed the do_not_update_load_defaults_in_app_update branch from dff4a8a to a4b9457 Compare February 10, 2018 12:23
@y-yagi
Copy link
Member Author

y-yagi commented Feb 10, 2018

The other option, instead of parsing the file, would be to remember the target_version inside load_defaults

👍 Yeah, that is a good approach. I updated.

@y-yagi y-yagi force-pushed the do_not_update_load_defaults_in_app_update branch from a4b9457 to 0defd1b Compare February 10, 2018 12:32
Incompatible settings are included in the settings set by `load_defaults`.
So, I think that target version should be updated by a user when becomes
available, and should not be updated with `app:update`.
@y-yagi y-yagi force-pushed the do_not_update_load_defaults_in_app_update branch from 0defd1b to 66b4752 Compare February 11, 2018 00:12
Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

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

Feel free to merge and backport

@y-yagi y-yagi merged commit 2c4e9c6 into rails:master Feb 12, 2018
@y-yagi y-yagi deleted the do_not_update_load_defaults_in_app_update branch February 12, 2018 22:13
y-yagi added a commit that referenced this pull request Feb 12, 2018
Incompatible settings are included in the settings set by `load_defaults`.
So, I think that target version should be updated by a user when becomes
available, and should not be updated with `app:update`.
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

4 participants