From 5a558c24f019d3c32f9ee957f5237a315779d7ec Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 24 Jul 2026 12:42:51 +0100 Subject: [PATCH] fix: minor issue --- application/templates/namespaces.py | 24 ++++++++++++------------ tests/test_namespaces.py | 12 ++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/application/templates/namespaces.py b/application/templates/namespaces.py index a44212dd..6c3bfddd 100644 --- a/application/templates/namespaces.py +++ b/application/templates/namespaces.py @@ -76,28 +76,28 @@ class SystemNamespace(NamespaceBuilder): deployments point it at an internal hostname (http://backend:7091) that would otherwise be advertised to end users. """ - global _platform_partial_content - try: - from application.core.settings import settings - from application.templates.template_engine import TemplateEngine + from application.core.settings import settings + from application.templates.template_engine import TemplateEngine - base = settings.PUBLIC_API_BASE_URL - api_base_url = ( - (base.strip().rstrip("/") or None) - if isinstance(base, str) and base.strip() - else None - ) + global _platform_partial_content + base = settings.PUBLIC_API_BASE_URL + api_base_url = ( + (base.strip().rstrip("/") or None) + if isinstance(base, str) and base.strip() + else None + ) + try: if _platform_partial_content is None: _platform_partial_content = _PLATFORM_PARTIAL_PATH.read_text(encoding="utf-8") platform = TemplateEngine().render( _platform_partial_content, {"api_base_url": api_base_url} ).strip() - return api_base_url, platform except Exception as e: logger.warning( f"Failed to build platform capabilities block: {e}", exc_info=True ) - return None, "" + platform = "" + return api_base_url, platform class PassthroughNamespace(NamespaceBuilder): diff --git a/tests/test_namespaces.py b/tests/test_namespaces.py index de47ff75..22220948 100644 --- a/tests/test_namespaces.py +++ b/tests/test_namespaces.py @@ -558,6 +558,18 @@ class TestSystemNamespacePlatform: assert "None" not in result["platform"] assert result["api_base_url"] is None + def test_api_base_url_survives_platform_render_failure(self): + from application.core.settings import settings + from application.templates.template_engine import TemplateEngine + + with ( + patch.object(settings, "PUBLIC_API_BASE_URL", "https://api.example.com"), + patch.object(TemplateEngine, "render", side_effect=RuntimeError("boom")), + ): + result = SystemNamespace().build() + assert result["platform"] == "" + assert result["api_base_url"] == "https://api.example.com" + def test_presets_render_platform_section(self): from pathlib import Path