FIX: Rescue ActiveRecord::ReadOnlyError when baking theme field (#29776)

Firstly, we need to understand that ActiveRecord can be
connected to a role which prevent writes and this happens in Discourse when a
replica database has been setup for failover purposes. When a role
prevent writes from happening, ActiveRecord will raise the
`ActiveRecord::ReadOnlyError` if a write query is attempted.

Secondly, theme fields are baked at runtime within GET requests. The
baking process involves writing the baked value to the
`ThemeField#baked_value` column in the database.

If we combine the two points above, we can see how the writing of the
baked value to the database will trigger a `ActiveRecord::ReadOnlyError`
in a GET requests when the database is connected to a role preventing
writes. However, failing to bake a theme is not the end of the world and
should not cause GET requests to fail. Therefore, this commit adds a rescue
for `ActiveRecord::ReadOnlyError` in the `ThemeField#ensure_baked!`
method.
This commit is contained in:
Alan Guo Xiang Tan
2024-11-15 10:19:10 +08:00
committed by GitHub
parent 4e5de17e7c
commit 6bf0ac730f
4 changed files with 40 additions and 0 deletions

View File

@@ -713,6 +713,7 @@ RSpec.configure do |config|
unfreeze_time
ActionMailer::Base.deliveries.clear
Discourse.redis.flushdb
Scheduler::Defer.do_all_work
end
config.after(:each, type: :system) do |example|