From 541b3f5570aa7a0500437725e17d47d01f2fb46a Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Tue, 23 Aug 2022 16:05:51 -0400 Subject: [PATCH] Specifically load a plugin's alembic_version from the database (#2170) * Specifically load a plugin's alembic_version from the database --- CTFd/plugins/migrations.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CTFd/plugins/migrations.py b/CTFd/plugins/migrations.py index 7b9393fa..56d46b05 100644 --- a/CTFd/plugins/migrations.py +++ b/CTFd/plugins/migrations.py @@ -8,7 +8,7 @@ from alembic.script import ScriptDirectory from flask import current_app from sqlalchemy import create_engine, pool -from CTFd.utils import get_config, set_config +from CTFd.utils import _get_config, set_config def current(plugin_name=None): @@ -20,7 +20,11 @@ def current(plugin_name=None): caller_path = caller_info[0] plugin_name = os.path.basename(os.path.dirname(caller_path)) - return get_config(plugin_name + "_alembic_version") + # Specifically bypass the cached config so that we always get the database value + version = _get_config.__wrapped__(plugin_name + "_alembic_version") + if version == KeyError: + version = None + return version def upgrade(plugin_name=None, revision=None, lower="current"): @@ -57,7 +61,7 @@ def upgrade(plugin_name=None, revision=None, lower="current"): # "current" points to the current plugin version stored in config # None represents the absolute base layer (e.g. first installation) if lower == "current": - lower = get_config(plugin_name + "_alembic_version") + lower = current(plugin_name) # Do we upgrade to head or to a specific revision if revision is None: