Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Exclude Drag and Drop blocks from the link-scanning step in the Course Optimizer #36321

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hinakhadim
Copy link

@hinakhadim hinakhadim commented Mar 4, 2025

Description:

This PR resolves the issue where the Course Optimizer fails with a "Link Check Failed" error when a Drag and Drop block is present in a course.

JIRA Link
test-course: https://course-authoring.stage.edx.org/course/course-v1:edx+jrr_103+H2_2023/optimizer

Issue Details:

  • The error occurred due to a TypeError: TypeError: expected string or bytes-like object, got 'dict'.
  • This was caused by the data field in Drag and Drop blocks, which is stored as a dictionary instead of a string.
  • The error was triggered in re.sub( , , xblock_data), where xblock_data expected a string but received an object.

Solution Implemented:

  • The fix excludes Drag and Drop blocks from the link-scanning process in the Course Optimizer.
  • This is done by checking the block type before processing its content.
  • The solution ensures that the optimizer can successfully scan other course content without failure.

Testing & Verification:

  • Verified the fix by running the optimizer on test courses with and without Drag and Drop blocks.
  • Confirmed that the scan completes successfully and broken links are detected as expected.

How to verify locally

  • Checkout this branch for edx-platform
  • Export test-course from stage environment and import on local devstack
  • run CMS and Cms-worker containers
  • Run course optimizer on test-course

Before

image

After

image

@hinakhadim hinakhadim self-assigned this Mar 4, 2025

urls = _scan_course_for_links(self.test_course.id)
# The drag-and-drop block should not appear in the results
assert all(block_id != str(drag_and_drop_block.usage_key) for block_id, _ in urls), \
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using keyword assert, you should follow the convention in this class to use self.assertFalse and other assert related functions.

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