Skip to content

Conversation

navinkarkera
Copy link
Contributor

@navinkarkera navinkarkera commented Sep 30, 2025

Description

Allows authors to migrate legacy library content block in course to library v2 if the source library was migrated. The block works with the new library and has the same functionality as the new ItemBankBlock.

This PR also fixes some issues with Problem Bank like Add components button not working in the preview page and iframe postMessage failure after syncing of component in the preview page.

screencast.mp4

Latest update in UI

screencast.mp4

Requirements as per The LegacyLibraryContentBlock OLX must work forever.

  • The LegacyLibraryContentBlock OLX must work forever.
  • L points at a legacy library, which has been migrated to a new V2 library.
    • Block Behavior: Preview and settings editor should look just like a modern ItemBank block.
    • Child Behavior: If updates are available (see below), they are shown per-child on the View page, using the migrated child blocks as the update source.
  • L points at a legacy library, which has not been migrated.
    • Block and Child Behavior: Use existing LegacyLibraryContentBlock interface behavior.
  • L is None, malformed, or doesn't point to an existing or migrated legacy library:
    • Block Behavior: Display a validation error. Syncing is not allowed. (existing behavior)
    • Child Behavior: Children are displayed if they exist, but no option to sync is offered.
      Sync behavior
  • The parent LegacyLibraryContentBlock's version does not equal the migrated source library version (indicating that the legacy library received updates before its migration happened)

Useful information to include:

  • Which edX user roles will this change impact? "Course Author" and "Developer"

Supporting information

Testing instructions

  • Create a legacy library with some components.
  • Add a legacy library content block in course unit.
  • Now migrate the legacy library.
  • Refresh the course unit page, a new alert should appear on top of the library content block.
  • Click on migrate button in the alert and verify that the block is migrated to Problem bank and behaves like it.
  • The children blocks have upstream field set and show sync button if the v2 library component is updated.

Deadline

"None" if there's no rush, or provide a specific date or event (and reason) if there is one.

Other information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.
  • If your database migration can't be rolled back easily.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Sep 30, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Sep 30, 2025

Thanks for the pull request, @navinkarkera!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Sep 30, 2025
@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch 3 times, most recently from 6dbd6db to 8c646c1 Compare October 2, 2025 11:23
@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from 7ad846c to 06de64c Compare October 2, 2025 11:48
Comment on lines 362 to 365
if self.is_source_lib_migrated_to_v2 and not self.is_migrated_to_v2:
# If the source library is migrated but this block still depends on legacy library
# Migrate the block by setting upstream field to all children blocks
self._v2_update_children_upstream_version()
Copy link
Member

Choose a reason for hiding this comment

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

@navinkarkera I'm not sure this is the best approach. The point of this method is to render the block, not to modify it--sticking the migration here is surprising and auto-magical. It will also update the children when the block is rendered in LMS, which would either fail or be a no-op, and would be confusing either way. In general, we should not be modifying content except in response to the action of a Studio user.

I had tried to outline an idea to follow library_content child references without a child migration process, but since writing that, I've also come to dislike the idea, because it would break the simplifying assumption that we can just check self.upstream on any block to see its upstream link. So, I like that your PR uses a migration child step, but I think we need some explicit way to trigger it.

Here's an idea:

  • When a legacy library_content block has (a) unmigrated chidlren and (b) a migrated source library, it gives the users the option to "sync" the latest content, regardless of whether are new changes in the target library.
  • Syncing, in this case, will migrate the children.

It's a slight product behavior change. In particular, every legacy library content block would have a "sync available" as soon as an operator migrates its source library. But, I think it would be worth the simplified behavior information architecture. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kdmccormick This is not the final version, locally I have something like this:
image

Sorry for the confusion.

Copy link
Contributor Author

@navinkarkera navinkarkera Oct 2, 2025

Choose a reason for hiding this comment

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

Once the author clicks on Migrate it looks like this:

image

I'll update the PR description once I push the changes.

Copy link
Member

Choose a reason for hiding this comment

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

Cool, thanks. I think this is a good approach. I'll ask precisely what the UI should be at the sync-up tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

looping UX into the discussion here: openedx/frontend-app-authoring#2386 (comment)

@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Oct 2, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Oct 2, 2025
@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from 82767cb to c2094f2 Compare October 3, 2025 11:51
@navinkarkera navinkarkera marked this pull request as ready for review October 3, 2025 14:13
@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from c2094f2 to d993b55 Compare October 4, 2025 06:29
Copy link
Contributor

@rpenido rpenido left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Thank you for your work, @navinkarkera !

  • I tested this using the instructions from the PR
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from d993b55 to 1f84fdc Compare October 7, 2025 10:23
Copy link
Contributor

@ChrisChV ChrisChV left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the great work!

@ChrisChV ChrisChV requested a review from kdmccormick October 7, 2025 18:18
@ChrisChV
Copy link
Contributor

ChrisChV commented Oct 7, 2025

@kdmccormick it's ready for another review

@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from 1f84fdc to eaf93f2 Compare October 8, 2025 10:01
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to In Eng Review in Contributions Oct 8, 2025
@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from eaf93f2 to f49a1d2 Compare October 9, 2025 16:28
Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

Looking pretty solid as a whole, but I'd like to see some more attention to the nitty details of code quality, especially around correctness of type annotations.

I'm on vacation until Oct 15, so if another reviewer is available before then to approve this, no need to wait on my approval.

return str(
LibraryUsageLocatorV2(lib_key, block_type=block_type, usage_id=usage_id) # type: ignore[abstract]
)
except (ValueError, TypeError):
Copy link
Member

Choose a reason for hiding this comment

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

Please catch exceptions that are more specific, and/or put fewer lines within the try clause. All sorts of things throw ValueError and TypeError; you could be unintentionally concealing bugs by catching like this.


def get_target_block_usage_keys(source_key: CourseKey | LibraryLocator) -> dict[UsageKey | None, str | None]:
"""
Get all target blocks for given list of source keys.
Copy link
Member

Choose a reason for hiding this comment

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

This does not say anything about what the keys are and what the value are--please be more descriptive.

}


def get_target_block_usage_keys(source_key: CourseKey | LibraryLocator) -> dict[UsageKey | None, str | None]:
Copy link
Member

Choose a reason for hiding this comment

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

This is saying that the keys of the return dictionary are of type UsageKey | None. Why would the key ever be None? That sounds like it'd be a bug.

Comment on lines 106 to 108
return str(
LibraryUsageLocatorV2(lib_key, block_type=block_type, usage_id=usage_id) # type: ignore[abstract]
)
Copy link
Member

Choose a reason for hiding this comment

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

Why stringify before returning? OpaqueKeys carry useful structure and type information. In this case, and in almost all other cases, it's best to pas around structured objects, and only convert to a string when it's absolutely necessary for serialization or display.

'source__key', 'target__key', 'target__learning_package__key'
)

def construct_usage_key(row: tuple[UsageKey | None, str, str]) -> str | None:
Copy link
Member

Choose a reason for hiding this comment

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

the first item of this 3-tuple is not a UsageKey | None. it's a str. Regardless of that, you're not even using it. Why pass it in at all? Instead of passing the whole row in, you could desctructure the row (for (source_key, target_local_key, target_learning_package_key) in query_set) and just pass in the data you need.

def construct_usage_key(row: tuple[UsageKey | None, str, str]) -> str | None:
try:
lib_key = LibraryLocatorV2.from_string(row[2])
_, block_type, usage_id = row[1].split(':')
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment describing the structure of row[1] so that the reader can understand what is happing in this parsing step.

Comment on lines 531 to 535
def validate(self):
"""
Validates the state of this ItemBankBlock Instance.
"""
return self._validate()
Copy link
Member

Choose a reason for hiding this comment

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

I see you renamed validate to _validate so that LegacyLibraryContentBlock could add custom validation behavior. But this is a textbook use of inheritance:, is it not? Instead of renaming, I think you could keep the original method named ItemBankMixin.validate, and then have a LegacyLibraryContentBlock.validate method which overrides it and calls super().validate(...) in order to use the base behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kdmccormick Yes, but we want to only use ItemBankMixin.validate() when the legacy block has been migrated else we want to use its parents, i.e. XBlock.validate() method.

Updated to use super() for migrated blocks and XBlock.validate() for unmigrated. See ecc6a0b

Comment on lines 102 to 103
# We cannot completely remove this block code until we force-migrate course content. Otherwise, we'll lose student
# data (such as selected fields), which tracks the children selected for each user.
Copy link
Member

@kdmccormick kdmccormick Oct 10, 2025

Choose a reason for hiding this comment

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

We will never force-migrate course content

Suggested change
# We cannot completely remove this block code until we force-migrate course content. Otherwise, we'll lose student
# data (such as selected fields), which tracks the children selected for each user.
# We can never completely remove the legacy library_content block; otherwise, we'd lose student
# data, such as selected fields, which tracks the children selected for each user.

@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch 2 times, most recently from 59d08a4 to 5786edc Compare October 13, 2025 14:06
@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch 2 times, most recently from ebe8f78 to d31584f Compare October 17, 2025 14:32
Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

🚀

@navinkarkera navinkarkera force-pushed the navin/fal-4251/legacy-lib-content-to-item-bank branch from d31584f to 9047bf7 Compare October 20, 2025 05:04
@navinkarkera navinkarkera merged commit 744cc87 into openedx:master Oct 20, 2025
49 checks passed
@navinkarkera navinkarkera deleted the navin/fal-4251/legacy-lib-content-to-item-bank branch October 20, 2025 05:50
@github-project-automation github-project-automation bot moved this from In Eng Review to Done in Contributions Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants