From: Vsevolod Stakhov Date: Tue, 16 Dec 2025 11:25:29 +0000 (+0000) Subject: [Fix] Fix Lua 5.4 compatibility in clickhouse and elastic plugins X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcd6cb7ee041ccdfb09c17d295bda66ea6c5f650;p=thirdparty%2Frspamd.git [Fix] Fix Lua 5.4 compatibility in clickhouse and elastic plugins - Merge nested settings tables (limits, retention) to preserve defaults when user provides partial configuration - Use %d with math.floor() instead of %.0f for integer formatting --- diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index 76586894f7..04803e1be0 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -1042,9 +1042,9 @@ local function clickhouse_maybe_send_data_periodic(cfg, ev_base, now) if last_collection > 0 and settings.limits.max_interval > 0 then if now - last_collection > settings.limits.max_interval then need_collect = true - reason = string.format('limit of time since last collection has been reached: %.0f seconds passed ' .. - '(%.0f seconds trigger)', - (now - last_collection), settings.limits.max_interval) + reason = string.format('limit of time since last collection has been reached: %d seconds passed ' .. + '(%d seconds trigger)', + math.floor(now - last_collection), math.floor(settings.limits.max_interval)) end end @@ -1408,6 +1408,10 @@ if opts then rspamd_logger.errx(rspamd_config, 'custom rule has no required attributes: schema, first_row and get_row') end end + elseif k == 'limits' or k == 'retention' then + for sk, sv in pairs(v) do + settings[k][sk] = sv + end else settings[k] = lua_util.deepcopy(v) end diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua index b26fbd8e84..6c59be685a 100644 --- a/src/plugins/lua/elastic.lua +++ b/src/plugins/lua/elastic.lua @@ -1518,9 +1518,24 @@ end local opts = rspamd_config:get_all_opt('elastic') +-- Merge nested tables to preserve defaults when user provides partial config +local function merge_settings(src, dst) + for k, v in pairs(src) do + if type(v) == 'table' and type(dst[k]) == 'table' then + merge_settings(v, dst[k]) + else + dst[k] = v + end + end +end + if opts then for k, v in pairs(opts) do - settings[k] = v + if type(v) == 'table' and settings[k] and type(settings[k]) == 'table' then + merge_settings(v, settings[k]) + else + settings[k] = v + end end if not settings['enabled'] then