Out-of-sync library components counted after unit deletion from course

Hi everyone,

I am observing an issue related to library sync and out-of-sync component counts in Open edX. The problem occurs in the following workflow. I add a unit from a library into a course, then modify some of the components inside that unit (for example, 4 out of 10 components modified in unit). Later, when I delete the entire unit from the course, I would expect that none of the components from that unit should contribute to the out-of-sync count anymore, since the unit is no longer present in the course structure.

However, in the current behavior, those modified components are still being counted as out-of-sync even after the unit has been deleted.
I have attached screenshot of out-of-sync panel present in course.

From my investigation, it appears that when the unit is deleted, the corresponding entry is removed from the ContainerLink table as expected, but the associated entries in the ComponentLink table are not removed. As a result, these component links remain in the system even though their downstream usage (the unit) no longer exists in the modulestore.

Due to this, when the downstream summary is computed using the logic:
Code chunk:-(DownstreamSummaryView class)

links = list(chain(
ComponentLink.filter_links(
downstream_context_key=course_key,
use_top_level_parents=True,
),
ContainerLink.filter_links(
downstream_context_key=course_key,
use_top_level_parents=True,
),
))

the ComponentLink.filter_links() call still returns these orphaned components, and they end up contributing to the out-of-sync count. This leads to an inflated count that includes components not actually present in the course anymore.

So how can we make sure to have proper count of out of sync library component?
Note:- We are using the Content Libraries V2(new Libraries)
@sarina , @joel.edwards , @arbrandes , @Sara_Burns , @FarazM

@braden @kmccormick @dave - could one of you take a look?

Thanks so much for the detailed report @Sliver_Horizon . I just opened an issue here: Out-of-sync library components counted after unit deletion from course · Issue #3091 · openedx/frontend-app-authoring · GitHub . We’ll take a look soon and hope to have it fixed in time for the Verawood release later this month.

I have a fix ready here: fix: ComponentLinks were not deleted when parent container was deleted by bradenmacdonald · Pull Request #38821 · openedx/openedx-platform · GitHub

If it looks good, I’ll merge it and then backport it to Verawood so it gets included in the release.