From 4d23f5b0fd9824c86ee79b090c19c8ddd34663e3 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Fri, 26 Jun 2026 16:05:18 -0400 Subject: [PATCH] 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 --- shopdb/plugins/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/shopdb/plugins/__init__.py b/shopdb/plugins/__init__.py index cf432c7..9b1d74e 100644 --- a/shopdb/plugins/__init__.py +++ b/shopdb/plugins/__init__.py @@ -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