Skip to content

Commit fcb2504

Browse files
committed
refactor: defer reverse_usage_url import to method scope to avoid LMS runtime dependency issues
1 parent e328d6c commit fcb2504

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

cms/djangoapps/contentstore/course_group_config.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from django.utils.translation import gettext as _
1111

12-
from cms.djangoapps.contentstore.utils import reverse_usage_url
1312
from common.djangoapps.util.db import MYSQL_MAX_INT, generate_int_id
1413
from lms.lib.utils import get_parent_unit
1514
from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition
@@ -118,6 +117,22 @@ def _get_usage_dict(course, unit, block, scheme_name=None):
118117
"""
119118
Get usage info for unit/block.
120119
"""
120+
# MIGRATION NELC NOTE:
121+
# This import was originally at the top of the file:
122+
# from cms.djangoapps.contentstore.utils import reverse_usage_url
123+
#
124+
# However, when the LMS loads this module (because we force CMS signal
125+
# registration in LMS via `from cms.djangoapps.contentstore.signals import handlers`) in eox-nelp,
126+
# importing `reverse_usage_url` at the top level triggers dependencies on
127+
# `openedx.core.djangoapps.content.search`, which does not exist in the LMS
128+
# context. This causes runtime errors when starting LMS.
129+
#
130+
# To fix this, we moved the import into `_get_usage_dict`, which is the only
131+
# method that uses it. This way:
132+
# - In CMS, the function still works normally.
133+
# - In LMS, the import is never executed, avoiding the error.
134+
from cms.djangoapps.contentstore.utils import reverse_usage_url
135+
121136
parent_unit = get_parent_unit(block)
122137

123138
if unit == parent_unit and not block.has_children:

0 commit comments

Comments
 (0)