Fix internal error when enabling a plugin

enable_plugin called register_blueprint at runtime, which Flask forbids after
the first request (AssertionError -> 500). Enabling now flips the registry flag
and fires on_enable best-effort; routes register on the next restart, symmetric
with disable. Nav reflects the re-enable immediately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-06-26 16:05:18 -04:00
parent 560527159a
commit 4d23f5b0fd

View File

@@ -257,11 +257,16 @@ class PluginManager:
self.registry.enable(name)
# Load the plugin
plugin = self.loader.load_plugin(name, self._app, self._db)
if plugin:
self._register_plugin_components(plugin)
plugin.on_enable(self._app)
# Fire the on_enable hook best-effort. Do NOT register the blueprint
# here: Flask forbids register_blueprint after the first request, so
# routes/nav for a re-enabled plugin take effect on the next restart
# (symmetric with disable).
try:
plugin = self.loader.load_plugin(name, self._app, self._db)
if plugin:
plugin.on_enable(self._app)
except Exception:
logger.exception(f"on_enable hook failed for plugin {name}")
logger.info(f"Enabled plugin: {name}")
return True