From 4338f555484314632562e684bf4fb9a2eb67a153 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Thu, 18 May 2023 14:40:12 -0400 Subject: [PATCH] fix: Load the DATA_DIR via derived_settings tooling. If we don't make the DATA_DIR a derived_setting, the only way to override it is to override the entirety of the MODULESTORE config, or override DATA_DIR in common.py in your fork. --- lms/envs/common.py | 5 +++-- lms/envs/minimal.yml | 4 ++++ lms/envs/production.py | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lms/envs/common.py b/lms/envs/common.py index 8d0ac13e4a..b80e0878ec 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1614,7 +1614,7 @@ MODULESTORE = { 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, 'OPTIONS': { 'default_class': 'xmodule.hidden_block.HiddenBlock', - 'fs_root': DATA_DIR, + 'fs_root': lambda settings: settings.DATA_DIR, 'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string', } }, @@ -1624,7 +1624,7 @@ MODULESTORE = { 'DOC_STORE_CONFIG': DOC_STORE_CONFIG, 'OPTIONS': { 'default_class': 'xmodule.hidden_block.HiddenBlock', - 'fs_root': DATA_DIR, + 'fs_root': lambda settings: settings.DATA_DIR, 'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string', } } @@ -1633,6 +1633,7 @@ MODULESTORE = { } } + DATABASES = { # edxapp's edxapp-migrate scripts and the edxapp_migrate play # will ensure that any DB not named read_replica will be migrated diff --git a/lms/envs/minimal.yml b/lms/envs/minimal.yml index f66dffc700..0688b7c49c 100644 --- a/lms/envs/minimal.yml +++ b/lms/envs/minimal.yml @@ -26,6 +26,10 @@ REST_FRAMEWORK: {} # off-machine storage to more easily scale the system. MEDIA_ROOT: "/tmp/edx-platform/media/" +# DATA_DIR is overridden twice in ./lms/envs/common.py override it here temporarily until that's cleaned up and we +# can default to something dev friendly and have overrides in production.py for production friendly settings. +DATA_DIR: "/tmp/edx-platform/data_dir" + # For just the CMS LMS_ROOT_URL: "http://localhost" LMS_INTERNAL_ROOT_URL: "http://localhost" diff --git a/lms/envs/production.py b/lms/envs/production.py index 342877206b..c8587f8fa6 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -490,6 +490,18 @@ XQUEUE_INTERFACE = AUTH_TOKENS.get('XQUEUE_INTERFACE', XQUEUE_INTERFACE) # Get the MODULESTORE from auth.json, but if it doesn't exist, # use the one from common.py MODULESTORE = convert_module_store_setting_if_needed(AUTH_TOKENS.get('MODULESTORE', MODULESTORE)) + +# After conversion above, the modulestore will have a "stores" list with all defined stores, for all stores, add the +# fs_root entry to derived collection so that if it's a callable it can be resolved. We need to do this because the +# `derived_collection_entry` takes an exact index value but the config file might have overidden the number of stores +# and so we can't be sure that the 2 we define in common.py will be there when we try to derive settings. This could +# lead to execptions being thrown when the `derive_settings` call later in this file tries to update settings. We call +# the derived_collection_entry function here to ensure that we update the fs_root for any callables that remain after +# we've updated the MODULESTORE setting from our config file. +for idx, store in enumerate(MODULESTORE['default']['OPTIONS']['stores']): + if 'OPTIONS' in store and 'fs_root' in store["OPTIONS"]: + derived_collection_entry('MODULESTORE', 'default', 'OPTIONS', 'stores', idx, 'OPTIONS', 'fs_root') + MONGODB_LOG = AUTH_TOKENS.get('MONGODB_LOG', {}) EMAIL_HOST_USER = AUTH_TOKENS.get('EMAIL_HOST_USER', '') # django default is ''