Skip to content

Commit

Permalink
Merge pull request #8954 from rtibbles/order_matters
Browse files Browse the repository at this point in the history
Fix upgrade issue
  • Loading branch information
marcellamaki committed Dec 20, 2021
2 parents e34205f + e68b9b6 commit ded2264
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
9 changes: 9 additions & 0 deletions kolibri/plugins/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
logger = logging.getLogger(__name__)


__initialized = False


class PluginExistsInApp(Exception):
"""
This exception is raise when a plugin is initialized inside a Django app and
Expand Down Expand Up @@ -163,6 +166,7 @@ def __initialize():
"""
Called once to register hook callbacks.
"""
global __initialized
registry = Registry()
logger.debug("Loading kolibri plugin registry...")
was_configured = settings.configured
Expand All @@ -171,7 +175,12 @@ def __initialize():
"Django settings already configured when plugin registry initialized"
)
registry.register_plugins(config.ACTIVE_PLUGINS)
__initialized = True
return registry


registered_plugins = SimpleLazyObject(__initialize)


def is_initialized():
return __initialized
10 changes: 10 additions & 0 deletions kolibri/plugins/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def autoremove_unavailable_plugins():
configured by the user or some other kind of hard dependency that should
make execution stop if not loadable.
"""
from kolibri.plugins.registry import is_initialized

if is_initialized():
# TODO: Turn this into a Runtime error
logger.warning("Attempted to updated plugins when registry is initialized")
changed = False
# Iterate over a copy of the set so that it is not modified during the loop
for module_path in config["INSTALLED_PLUGINS"].copy():
Expand All @@ -415,6 +420,11 @@ def enable_new_default_plugins():
default plugins that have been explicitly disabled by a user,
in versions prior to the implementation of a plugin blacklist.
"""
from kolibri.plugins.registry import is_initialized

if is_initialized():
# TODO: Turn this into a Runtime error
logger.warning("Attempted to updated plugins when registry is initialized")
changed = False
for module_path in DEFAULT_PLUGINS:
if module_path not in config["INSTALLED_PLUGINS"]:
Expand Down
15 changes: 8 additions & 7 deletions kolibri/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
from logging.handlers import TimedRotatingFileHandler

from . import conf


GET_FILES_TO_DELETE = "getFilesToDelete"
DO_ROLLOVER = "doRollover"
Expand Down Expand Up @@ -105,11 +103,14 @@ def filter(self, record):
return False


class RequireDebugTrue(logging.Filter):
"""A copy from Django to avoid loading Django's settings stack"""
def get_require_debug_true(debug):
class RequireDebugTrue(logging.Filter):
"""A copy from Django to avoid loading Django's settings stack"""

def filter(self, record):
return conf.OPTIONS["Server"]["DEBUG"]
def filter(self, record):
return debug

return RequireDebugTrue


def get_default_logging_config(LOG_ROOT, debug=False, debug_database=False):
Expand Down Expand Up @@ -227,7 +228,7 @@ def get_base_logging_config(LOG_ROOT, debug=False, debug_database=False):
config = get_default_logging_config(
LOG_ROOT, debug=debug, debug_database=debug_database
)
config["filters"]["require_debug_true"] = {"()": RequireDebugTrue}
config["filters"]["require_debug_true"] = {"()": get_require_debug_true(debug)}

return config

Expand Down
16 changes: 9 additions & 7 deletions kolibri/utils/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,21 @@ def _upgrades_before_django_setup(updated, version):
if version and updated:
check_plugin_config_file_location(version)

# Do this here so that we can fix any issues with our configuration file before
# we attempt to set up django.
autoremove_unavailable_plugins()

if updated:
# Reset the enabled plugins to the defaults
# This needs to be run before dbbackup because
# dbbackup relies on settings.INSTALLED_APPS
enable_new_default_plugins()

# Ensure that we have done all manipulations of our plugins registry before
# we do the check for options.ini as that will invoke our plugin registry.
# Check if there is an options.ini file exist inside the KOLIBRI_HOME folder
check_default_options_exist()

if OPTIONS["Database"]["DATABASE_ENGINE"] == "sqlite":
# If we are using sqlite,
# we can shortcut migrations by using the preseeded databases
Expand Down Expand Up @@ -256,13 +265,6 @@ def initialize(

handle_default_options(default_options)

# Do this here so that we can fix any issues with our configuration file before
# we attempt to set up django.
autoremove_unavailable_plugins()

# Check if there is an options.ini file exist inside the KOLIBRI_HOME folder
check_default_options_exist()

version = get_version()

updated = version_updated(kolibri.__version__, version)
Expand Down

0 comments on commit ded2264

Please sign in to comment.