GlobalSetting.use_s3? - false

AI-generated summary

In a self-hosting support discussion about S3 configuration, eextra reports that GlobalSetting.use_s3? returns false despite S3 being configured correctly for new uploads, and seeks help migrating existing uploads using rake uploads:migrate_to_s3. They attempted to set S3 credentials via discourse.conf, but riking clarifies these should be in the env: section of app.yml. Even after setting GlobalSetting.use_s3? to true in the Rails console, the migration still fails. neounix explains that GlobalSetting values are read-only at runtime — they cannot be assigned dynamically like SiteSetting values. Demonstrating this, they show that attempting to assign GlobalSetting.use_s3 = true raises a NoMethodError, confirming global settings are fixed at build time. This architectural distinction — global settings being immutable post-deployment for security and stability — is likely why eextra’s attempt failed. The solution requires ensuring S3 is correctly configured in app.yml before rebuilding the container, not adjusted via console.

Try to solve the problem with file migration to s3. The first thing is that the command returns

 GlobalSetting.use_s3?
 false

And now the question. If loading new images works (i.e. S3 is set well) then what causes this error (I want to transfer existing images with DRY_RUN=1 rake uploads:migrate_to_s3) ?

Should I set something apart from the settings in the admin panel
I tried to edit discourse.conf like this:

DISCOURSE_S3_BUCKET=00000 \
DISCOURSE_S3_REGION=eu-west-2 \
DISCOURSE_S3_ACCESS_KEY_ID=00000 \
DISCOURSE_S3_SECRET_ACCESS_KEY=00000 \

file but it didn’t work.

Those are formatted like environment variables. They should be in the env: section of your app.yml.

I set it rigth now (GlobalSetting.use_s3? true )

Unfortunately, still the same mistake. Command rake uploads:migrate_to_s3 returns the error

If I am not mistaken, you cannot change global settings from the rails console; but you can change site settings from the console:

Basice example changing site setting:

pry(main)> SiteSetting.site_description
=> "My Cool Site"

pry(main)> SiteSetting.site_description = "My Great Discourse Site"
=> "My Great Discourse Site"

pry(main)> SiteSetting.site_description
=> "My Great Discourse Site"

A specific example, comparing global settings with site settings:

pry(main)> GlobalSetting.force_https
=> true

pry(main)> SiteSetting.force_https = false
false

pry(main)> SiteSetting.force_https
=> false

pry(main)> SiteSetting.force_https = true
=> true

pry(main)> GlobalSetting.force_https
=> true

pry(main)> GlobalSetting.force_https = false
NoMethodError: undefined method `force_https=' for GlobalSetting:Class
Did you mean? force_https
from (pry):61:in `__pry__'

pry(main)> GlobalSetting.force_https = true
NoMethodError: undefined method `force_https=' for GlobalSetting:Class
Did you mean? force_https
from (pry):62:in `__pry__'

When I did this type of testing from the rails console, it led me to believe that global settings cannot be changed in the application after the application is build; however site settings can be changed in the app after it is build and running.

For example, the developer email addresses are set in the container yml file, and this value cannot be changed in the app, which adds a layer of security to the site.

In some cases, we see that a global setting is assigned to a site setting, and then the site setting is used in the app and so it can be changed; however, when the global setting is used in the app, this value cannot be changed (or so it seems during testing).

This appears, based on my limited testing, to be one of the fundamental differences between global settings and site settings.

So, I think this is the underlying reason when @eextra tried to set GlobalSetting.use_s3? true, they found it did not work as expected:

pry(main)> GlobalSetting.use_s3?
=> false

pry(main)> GlobalSetting.use_s3 = true
NoMethodError: undefined method `use_s3=' for GlobalSetting:Class
Did you mean?  use_s3?
from (pry):8:in `__pry__'