From 7a95943ad723c4a74fcf2603360671bf1932b8fa Mon Sep 17 00:00:00 2001 From: mirivlad Date: Mon, 8 Jun 2026 14:15:37 +0800 Subject: [PATCH] fix(plugins): empty Lua tables now serialize as [] instead of {} in luaValueToGo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Empty Lua tables from DB queries (e.g. get_events with no results) are ambiguous — they could be [] or {}. Frontend expects arrays (with .length), so we default empty tables to [] instead of {}. --- internal/core/plugins/api_utils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/core/plugins/api_utils.go b/internal/core/plugins/api_utils.go index 93531fe..e002b0d 100644 --- a/internal/core/plugins/api_utils.go +++ b/internal/core/plugins/api_utils.go @@ -81,6 +81,16 @@ func luaValueToGo(v lua.LValue) interface{} { } return arr } + // Check if table has any keys at all — empty tables are ambiguous. + // DB queries return empty tables when no rows match; the frontend + // expects a valid array [] (with .length), not {} (where .length is undefined). + hasKeys := false + val.ForEach(func(k lua.LValue, v lua.LValue) { + hasKeys = true + }) + if !hasKeys { + return make([]interface{}, 0) + } m := make(map[string]interface{}) val.ForEach(func(k lua.LValue, v lua.LValue) { m[fmt.Sprintf("%v", k)] = luaValueToGo(v)