fix(plugins): a plugin that can't start live says why and offers a restart (#6087)
CI / lint (push) Successful in 2s
CI / unit (push) Successful in 1m28s
CI / integration (push) Successful in 1m33s
CI / publish (push) Successful in 1m29s

Saving an enabled plugin threw away hot_reload_plugin's (ok, message), so a
plugin that failed to load live read "Enabled, not loaded" with nothing
more. Now:
- a live-load failure is recorded with its reason, as a boot failure is, and
  logged; a later success clears it;
- any save of an enabled plugin that isn't running tries to start it, not
  only the off-to-on toggle;
- enabling one already running is a success, not a failure;
- the plugin's page offers "Restart to load" while it is enabled and not
  running.

Quart never marks the app as having served its first request, so
register_blueprint after startup is allowed: hot-loading is not refused
wholesale, as #6087 suspected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-18 22:56:54 -04:00
co-authored by Claude Opus 5.5
parent f7616b71c3
commit a59d1a7709
4 changed files with 102 additions and 8 deletions
+19 -6
View File
@@ -305,16 +305,29 @@ def load_plugins(app: "Quart") -> None:
def hot_reload_plugin(app: "Quart", name: str) -> tuple[bool, str]:
"""Activate a plugin that was just enabled without restarting the app.
This works for plugins that were NOT previously loaded. For plugins that
are already registered (blueprint already mounted), a full restart is
required to pick up code changes — use restart_app() in that case.
A plugin that can't be loaded live is recorded with its reason, as a
failed boot load is, so its settings page says why and offers a restart
rather than reading "Enabled, not loaded" with nothing more (#6087).
Returns (success, message).
"""
ok, message = _hot_load(app, name)
if ok:
_FAILED_PLUGINS.pop(name, None)
else:
_FAILED_PLUGINS[name] = message
logger.warning("Plugin %r could not be loaded live: %s", name, message)
return ok, message
def _hot_load(app: "Quart", name: str) -> tuple[bool, str]:
"""Load one plugin into the running app. A plugin already loaded (enabled,
disabled and enabled again without a restart) is still running, so that
is a success; picking up its code changes needs restart_app()."""
import steward
if name in _LOADED_PLUGINS:
return False, "Plugin already loaded — restart required to apply updates"
return True, "Plugin already running"
plugin_dirs = [Path(d).resolve() for d in app.config["PLUGIN_DIRS"]]
plugin_path = resolve_plugin_path(plugin_dirs, name)
@@ -373,9 +386,9 @@ def hot_reload_plugin(app: "Quart", name: str) -> tuple[bool, str]:
)
all_dirs = discover_all_in(plugin_dirs)
run_plugin_migrations(app.config["DATABASE_URL"], all_dirs)
except Exception:
except Exception as exc:
logger.exception("Plugin %r: migration failed during hot-reload", name)
return False, "Migration failed — check logs"
return False, f"Migration failed: {exc}"
# Import (file-path load avoids stdlib name collisions)
try: