Skip to content

fix: Multi Select course/course run issue#4704

Open
skumargupta83 wants to merge 1 commit intoopenedx:masterfrom
skumargupta83:bug/CATALOG-44
Open

fix: Multi Select course/course run issue#4704
skumargupta83 wants to merge 1 commit intoopenedx:masterfrom
skumargupta83:bug/CATALOG-44

Conversation

@skumargupta83
Copy link
Contributor

https://2u-internal.atlassian.net/browse/CATALOG-44

Unable to Enter Course and Org Data- Discovery

Description

A recent update in the Discovery is preventing users from entering information in the Courses and Authoring Organization fields. This is impacting high-priority program operations, specifically for Google Cloud initiatives that require quick turnaround. The affected user reported being unable to input necessary data in these fields and requests an urgent resolution to restore data entry capabilities

Acceptance Criteria :

The Courses and Authoring Organization fields must allow data entry without errors for all users.
No existing programs or scheduled launches should be disrupted during the patch or rollback.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR attempts to fix an issue where users cannot enter data in Course and Authoring Organization fields in the Django admin interface. The changes include modifications to the autocomplete widget and admin class configurations to ensure proper Select2 JavaScript library loading. However, the PR contains critical issues related to non-existent Django versions.

Changes:

  • Updated Django version in requirements (to a non-existent version 5.2.6)
  • Modified SortedModelSelect2Multiple widget to include both selected and non-selected items in optgroups
  • Added DALAdminMixin to ensure Select2 assets load correctly for CourseAdmin and ProgramAdmin
  • Added documentation explaining the fixes

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
requirements/django.txt Upgrades Django version to 5.2.6 (which does not exist)
course_discovery/apps/course_metadata/widgets.py Updated optgroups to include non-selected items for search functionality, added media property and get_context method
course_discovery/apps/course_metadata/admin.py Added DALAdminMixin and updated CourseAdmin and ProgramAdmin to use it, added Media classes with Select2 assets
DJANGO_5_2_SELECT2_FIX.md Documentation explaining the Select2 JavaScript loading fix (references non-existent Django versions)
DJANGO_5_2_MIGRATION_FIX.md Documentation explaining widget migration changes (references non-existent Django versions)
Comments suppressed due to low confidence (2)

course_discovery/apps/course_metadata/admin.py:270

  • The Media class defined here duplicates the Media class already defined in the DALAdminMixin at lines 70-81. Since CourseAdmin now inherits from DALAdminMixin (line 161), this Media class will be merged with the mixin's Media class. This duplication is redundant and could lead to the same assets being loaded twice. Consider removing this Media class definition and relying solely on the DALAdminMixin's Media class, or if additional assets are needed, only include those that are not already in the mixin.
    class Media:
        css = {
            'all': (
                'admin/css/autocomplete.css',
                'select2/dist/css/select2.css',
                'dal_select2/dist/css/choices.css',
            )
        }
        js = (
            'select2/dist/js/select2.js',
            'admin/js/autocomplete.js',
            'bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
            'bower_components/jquery/dist/jquery.min.js',
            SortableSelectJSPath()
        )

course_discovery/apps/course_metadata/admin.py:630

  • Similar to CourseAdmin, this Media class duplicates the Media class already defined in the DALAdminMixin at lines 70-81. Since ProgramAdmin now inherits from DALAdminMixin (line 476), this duplication is redundant. Consider removing this Media class and relying on the mixin, or only including additional assets that are not already in the mixin.
    class Media:
        css = {
            'all': (
                'admin/css/autocomplete.css',
                'select2/dist/css/select2.css',
                'dal_select2/dist/css/choices.css',
            )
        }
        js = (
            'select2/dist/js/select2.js',
            'admin/js/autocomplete.js',
            'bower_components/jquery-ui/ui/minified/jquery-ui.min.js',
            'bower_components/jquery/dist/jquery.min.js',
            SortableSelectJSPath()
        )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to +23
for value_id in value:
for item in selected:
if value_id == str(item[1][0]['value']):
# item is a tuple: (group_name, [{'value': ..., 'label': ..., ...}], index)
if item[1] and len(item[1]) > 0:
if value_id == str(item[1][0]['value']):
ordered.append(item)
added_ids.add(value_id)
break
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optgroups method assumes that items in the selected list always have a non-empty second element (item[1]). However, this safety check should be performed before attempting to access item[1][0]['value']. If item[1] is empty or None, this will cause an IndexError. Consider adding the check before the value_id comparison or restructuring the logic to handle empty items more gracefully.

Copilot uses AI. Check for mistakes.
return ordered

@property
def media(self):
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The media property simply returns the parent's media without adding any documentation or explanation. While this is functionally correct, the inline comment in DJANGO_5_2_MIGRATION_FIX.md suggests this is necessary for Django compatibility. Consider adding a docstring explaining why this explicit property is needed, as it would help future maintainers understand its purpose.

Suggested change
def media(self):
def media(self):
"""
Explicitly expose the parent's media for this widget.
This override is intentionally kept, even though it simply returns ``super().media``,
to satisfy Django's expectations around widget media in newer versions.
See ``DJANGO_5_2_MIGRATION_FIX.md`` for additional context.
"""

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +87
Removed the non-existent import and ensured proper media inheritance:
- Removed: `from django.forms.widgets import MediaDefiningWidget`
- Added: Proper media property and get_context override for Django 5.2
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states that the import "from django.forms.widgets import MediaDefiningWidget" was removed, but this import does not appear in the current diff of widgets.py. If this was removed in a previous change, this documentation is outdated or referencing the wrong change.

Suggested change
Removed the non-existent import and ensured proper media inheritance:
- Removed: `from django.forms.widgets import MediaDefiningWidget`
- Added: Proper media property and get_context override for Django 5.2
Updated widget media handling to ensure proper inheritance and Django 5.2 compatibility:
- Ensured widget media is defined correctly for Django 5.2 admin behavior
- Verified that autocomplete-related assets are included via the widget media configuration

Copilot uses AI. Check for mistakes.
@@ -1 +1 @@
django==4.2.23
django==5.2.6
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description states this fix addresses "a recent update in the Discovery preventing users from entering information" in course fields. However, this PR includes a Django version upgrade from 4.2.23 to 5.2.6 (which doesn't exist). If the issue was caused by a recent Django upgrade, it should be documented which actual version was upgraded to. If this is not a version upgrade PR but rather a fix for an existing issue, the Django version change should be in a separate PR or explained in the description.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants