mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 03:19:10 +00:00
DEV: Do not attempt to overwrite UserOption enums during autoloading (#22150)
Unfortunately, Discourse's `UserOption` model is not currently autoloaded. That means that modifying it via a `reloadable_patch` will try to apply the changes repeatedly. Normally this doesn't matter since the changes are idempotent. However, introducing ActiveRecord enums is not idempotent - they raise an error if the same enum already exists on the model. This commit adds a check to avoid hitting this 'duplicate definition' error. Reproduced ``` rails runner 'Rails.application.reloader.reload!' ```
This commit is contained in:
parent
ab286cc6e1
commit
54cae1299e
@ -18,8 +18,13 @@ module Chat
|
||||
@chat_header_indicator_preferences ||= { all_new: 0, dm_and_mentions: 1, never: 2 }
|
||||
end
|
||||
|
||||
base.enum :chat_email_frequency, base.chat_email_frequencies, prefix: "send_chat_email"
|
||||
base.enum :chat_header_indicator_preference, base.chat_header_indicator_preferences
|
||||
if !base.method_defined?(:send_chat_email_never?) # Avoid attempting to override when autoloading
|
||||
base.enum :chat_email_frequency, base.chat_email_frequencies, prefix: "send_chat_email"
|
||||
end
|
||||
|
||||
if !base.method_defined?(:never?) # Avoid attempting to override when autoloading
|
||||
base.enum :chat_header_indicator_preference, base.chat_header_indicator_preferences
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user