From 768c8936626ab5e982d2bcc0a312b5a21e425d56 Mon Sep 17 00:00:00 2001 From: Florian Haas Date: Thu, 2 Jan 2025 15:43:05 +0100 Subject: [PATCH] feat: Add a plausibility check for Meilisearch configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tutor is meant to be configured with either its own, or an externally preconfigured Meilisearch instance. Thus, the combination of configuring RUN_MEILISEARCH: false and leaving MEILISEARCH_URL at its default is almost certainly a configuration error. Add an alert to notify the user of that configuration issue. Related issue: https://github.com/overhangio/tutor/issues/1185 --- ...0250102_163724_fghaas_check_meilisearch.md | 1 + tutor/config.py | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 changelog.d/20250102_163724_fghaas_check_meilisearch.md diff --git a/changelog.d/20250102_163724_fghaas_check_meilisearch.md b/changelog.d/20250102_163724_fghaas_check_meilisearch.md new file mode 100644 index 0000000000..ddd48b0e20 --- /dev/null +++ b/changelog.d/20250102_163724_fghaas_check_meilisearch.md @@ -0,0 +1 @@ +- [Improvement] Add a plausibility check that issues a warning if `RUN_MEILISEARCH` is `false` but `MEILISEARCH_URL` is unset. (by @fghaas) diff --git a/tutor/config.py b/tutor/config.py index 5d29c17f40..be6fc3cfee 100644 --- a/tutor/config.py +++ b/tutor/config.py @@ -358,3 +358,23 @@ def _check_preview_lms_host(config: Config) -> None: f'Warning: PREVIEW_LMS_HOST="{preview_lms_host}" is not a subdomain of LMS_HOST="{lms_host}". ' "This configuration is not typically recommended and may lead to unexpected behavior." ) + + +@hooks.Actions.CONFIG_LOADED.add() +def _check_run_meilisearch(config: Config) -> None: + """ + In case RUN_MEILISEARCH is set to false, check if + MEILISEARCH_URL has been set to a non-default value. + If not, print a warning to notify the user. + """ + + run_meilisearch = get_typed(config, "RUN_MEILISEARCH", bool, True) + if not run_meilisearch: + meilisearch_url = get_typed(config, "MEILISEARCH_URL", str, "") + meilisearch_url_default = get_defaults()["MEILISEARCH_URL"] + if meilisearch_url == meilisearch_url_default: + fmt.echo_alert( + "Warning: RUN_MEILISEARCH is false, but MEILISEARCH_URL is unset. " + "This configuration is not typically recommended and may lead to unexpected behavior. " + "Consider setting RUN_MEILISEARCH, or setting MEILISEARCH_URL to an existing, preconfigured Meilisearch instance." + )