From b532548d19e15ed51bbdab4be9241232141c633f Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 30 May 2026 11:34:13 +0800 Subject: [PATCH] fix: keep previous rp_caches when DB returns empty result sqlExe can return [] without raising an exception (bad connection, cursor issue). When load_roleperms gets 0 records but had valid cache before, keep the old cache instead of replacing with {}. Prevents intermittent 403 from transient DB issues. --- rbac/userperm.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rbac/userperm.py b/rbac/userperm.py index 5408687..aa01a70 100644 --- a/rbac/userperm.py +++ b/rbac/userperm.py @@ -246,6 +246,10 @@ where a.permid = b.id and c.id = a.roleid order by c.orgtypeid, c.name""" recs = await sor.sqlExe(sql_all, {}) + if len(recs) == 0 and self.rp_caches: + # DB returned empty — likely a bad connection. Keep previous valid cache. + debug(f'load_roleperms: got 0 records, keeping previous cache ({sum(len(v) for v in self.rp_caches.values())} paths)') + return for r in recs: if r.id == 'anonymous': k = 'anonymous'