fix: rbac cache clear - get actual instance from ServerEnv, not new one; uapi also clear apikeys

This commit is contained in:
yumoqing 2026-06-01 17:18:20 +08:00
parent 42eff6cda0
commit 4e19bb8d06

View File

@ -219,13 +219,19 @@ def invalidate_all_caches():
""" """
cleared = [] cleared = []
# rbac: UserPermissions singleton with LRU caches # rbac: UserPermissions is NOT a singleton — the actual instance is
# stored on ServerEnv by load_rbac(). Must get that instance, not
# create a new one (which would have empty caches).
try: try:
from rbac.userperm import UserPermissions from ahserver.serverenv import ServerEnv
up = UserPermissions() g = ServerEnv()
up.ur_caches.clear() up = getattr(g, 'userpermissions', None)
up.invalidate_rp_cache() if up is not None:
cleared.append('rbac') up.ur_caches.clear()
up.invalidate_rp_cache()
cleared.append('rbac')
else:
debug('[hot_reload] rbac: userpermissions not found on ServerEnv')
except Exception as e: except Exception as e:
debug(f'[hot_reload] rbac cache clear skipped: {e}') debug(f'[hot_reload] rbac cache clear skipped: {e}')
@ -237,12 +243,13 @@ def invalidate_all_caches():
except Exception as e: except Exception as e:
debug(f'[hot_reload] pricing cache clear skipped: {e}') debug(f'[hot_reload] pricing cache clear skipped: {e}')
# uapi: UAPIData singleton with apidata and org_users dicts # uapi: UAPIData singleton (@SingletonDecorator) with 3 cache dicts
try: try:
from uapi.apidata import UAPIData from uapi.apidata import UAPIData
ud = UAPIData() ud = UAPIData()
ud.apidata.clear() ud.apidata.clear()
ud.org_users.clear() ud.org_users.clear()
ud.apikeys.clear()
cleared.append('uapi') cleared.append('uapi')
except Exception as e: except Exception as e:
debug(f'[hot_reload] uapi cache clear skipped: {e}') debug(f'[hot_reload] uapi cache clear skipped: {e}')