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
Fixes #27585 - default dns timeout value is nil #7260
Conversation
Issues: #27585 |
971c0c5
to
7f2c88a
Compare
Rebased. |
7f2c88a
to
c730442
Compare
This is what I think should fix it. I will be honest - I don't have time for full 1.23 installation with upgrade to 1.24 and reproducing this. So I made the seed task as generic as possible - when anything is not expected it tries to fix it. |
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 seeds are not intended for migrations. Seeds are for providing initial data. This will also be executed on every single upgrade and test run where migrations are only executed once. 👎 from me.
I'm trying to follow where migrations fall down given the intent is to migrate data from one state to another. If settings are not created until Rails starts for the first time, maybe that design is more the problem. Just thinking a bit outloud because we've been having discussions about how seeds are used for a variety of functions and are hard to track. |
I agree with @ekohl, we do have a lot of data changes in migrations. Seeds are for creating the initial state, not modifying the existing state. |
If I'm not mistaken, settings are initialized before first migration runs. Rails environment is already loaded in migrations. Therefore, Setting should always be there. The migration just needs to check, if the old setting is present and if that's the case, migrate it. If not, it means this was new deployment and the setting is initialized correctly from the first step. So I guess, we just need to move the code from seed to migration? |
@lzap what's the status here? iiuc the consensus is that we shouldn't do that in the seed, but rather fix in a migration. since if we serialized nil into the value we would get: Setting.find_by_name('dns_timeout')[:value] #=> "--- \n"
Setting[:dns_timeout] #=> nil Therefor, the fix for this should be as simple as a migration that does: Setting.find_by_name('dns_timeout').update_column(:value, nil) if Setting[:dns_timeout].nil? |
to reproduce the original issue, run Setting.find_by_name('dns_timeout').update_column(:value, nil.to_yaml) |
Is it just me who thinks that all settings (including those managed by UI/API/CLI) should be stored in plain files (Yaml, JSON or whatever does not matter)? Number one offender in ActiveRecord instance allocation is Settings model, no surprise. It's slow. We need to cache it. It's not practical. And migrations are challenge (serialization would not necessary improve that tho). |
@tbrisker hmmm this does not appear to work:
|
Ok so the correct statement is:
|
c730442
to
00f922c
Compare
This should do it then if you prefer migrations. |
that's exactly what it should be displaying, if you check |
00f922c
to
9dbaa47
Compare
ECOFFEE rebased. |
class CorrectDnsTimeoutSetting < ActiveRecord::Migration[5.2] | ||
def up | ||
unless Setting[:dns_timeout].is_a?(Integer) || Setting[:dns_timeout].is_a?(Array) | ||
Setting.find_by_name('dns_timeout').update_column(:value, 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.
Looks like this fails if the settings haven't been initialized yet, let's be defensive:
Setting.find_by_name('dns_timeout').update_column(:value, nil) | |
Setting.find_by_name('dns_timeout')&.update_column(:value, 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.
Facepalm rebased.
9dbaa47
to
d7512fb
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.
Thanks @lzap !
1.24 - 4ddb8c0 |
This should fix the issue and sets up a new way we should be "migrating"
settings. These settings operations are usually:
In my case this is both, but the idea is to simply do this during seed
instead of Rails migration which is very clunky because Rails
migrations:
A seed script will always happen after settings are initialized and are
the right tool for the job. Migrations should manipulate schemas, seed
scripts should manipulate data.