FIX Read-Modify-Write issue with dynamic fields (#290)

* FIX Read-Modify-Write issue with dynamic fields

Ruby caching + queueing updates might cause some dynamic fields to not be updated.

* Small fix for true dynamic fields

* Add suite of tests for new settings page

* Treat nil values as deletions to keep the hash clean

* Test fix
This commit is contained in:
soky srm
2025-11-05 12:19:33 +01:00
committed by GitHub
parent b4e4c37834
commit 164fe5375d
3 changed files with 382 additions and 5 deletions

View File

@@ -70,10 +70,14 @@ class Setting < RailsSettings::Base
if respond_to?("#{key_str}=")
public_send("#{key_str}=", value)
else
# Otherwise, store in dynamic_fields hash
# Otherwise, manage in dynamic_fields hash
current_dynamic = dynamic_fields.dup
current_dynamic[key_str] = value
self.dynamic_fields = current_dynamic
if value.nil?
current_dynamic.delete(key_str) # treat nil as delete
else
current_dynamic[key_str] = value
end
self.dynamic_fields = current_dynamic # persists & busts cache
end
end