Skip to content

Commit 9df60f2

Browse files
fix: log warning when INSTRUCTOR_MICROFRONTEND_URL is unset (#37999)
1 parent b98e41e commit 9df60f2

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

lms/djangoapps/instructor/tests/test_api_v2.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,25 @@ def test_course_errors_from_modulestore(self, mock_modulestore):
425425
self.assertIn('course_errors', response.data)
426426
self.assertIsInstance(response.data['course_errors'], list)
427427

428+
@patch('lms.djangoapps.instructor.views.serializers_v2.settings.INSTRUCTOR_MICROFRONTEND_URL', None)
429+
def test_tabs_log_warning_when_mfe_url_not_set(self):
430+
"""
431+
Test that a warning is logged when INSTRUCTOR_MICROFRONTEND_URL is not set.
432+
"""
433+
with self.assertLogs('lms.djangoapps.instructor.views.serializers_v2', level='WARNING') as cm:
434+
tabs = self._get_tabs_from_response(self.staff)
435+
436+
self.assertTrue(
437+
any('INSTRUCTOR_MICROFRONTEND_URL is not set' in msg for msg in cm.output)
438+
)
439+
# Tab URLs should use empty string as base, not "None"
440+
for tab in tabs:
441+
self.assertFalse(tab['url'].startswith('None'), f"Tab URL should not start with 'None': {tab['url']}")
442+
self.assertTrue(
443+
tab['url'].startswith('/instructor/'),
444+
f"Tab URL should start with '/instructor/': {tab['url']}"
445+
)
446+
428447
def test_pacing_self_for_self_paced_course(self):
429448
"""
430449
Test that pacing is 'self' for self-paced courses.

lms/djangoapps/instructor/views/serializers_v2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Following REST best practices, serializers encapsulate most of the data processing logic.
66
"""
77

8+
import logging
9+
810
from django.conf import settings
911
from django.db.models import Count
1012
from django.utils.html import escape
@@ -33,6 +35,8 @@
3335

3436
from .tools import get_student_from_identifier, parse_datetime, DashboardError
3537

38+
log = logging.getLogger(__name__)
39+
3640

3741
class CourseInformationSerializerV2(serializers.Serializer):
3842
"""
@@ -75,6 +79,10 @@ def get_tabs(self, data):
7579
course_key = course.id
7680
mfe_base_url = settings.INSTRUCTOR_MICROFRONTEND_URL
7781

82+
if not mfe_base_url:
83+
log.warning('INSTRUCTOR_MICROFRONTEND_URL is not set.')
84+
mfe_base_url = ''
85+
7886
access = {
7987
'admin': request.user.is_staff,
8088
'instructor': bool(has_access(request.user, 'instructor', course)),

lms/envs/devstack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
398398
AUTHN_MICROFRONTEND_URL = 'http://localhost:1999'
399399
AUTHN_MICROFRONTEND_DOMAIN = 'localhost:1999'
400400
EXAMS_DASHBOARD_MICROFRONTEND_URL = 'http://localhost:2020'
401+
INSTRUCTOR_MICROFRONTEND_URL = 'http://localhost:2003'
401402
CATALOG_MICROFRONTEND_URL = 'http://localhost:1998/catalog'
402403

403404
################### FRONTEND APPLICATION DISCUSSIONS ###################

0 commit comments

Comments
 (0)