From e553ec0fdcaca73a7dd5f60cb4ce2350a217b41e Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Thu, 10 Oct 2024 16:15:03 +0530 Subject: [PATCH] fix: use get_components in m2m_changed signal handler Using `get_collection_components` does not work in case of post_remove as the component is already removed from collection and we don't really need additional filtering as we already have pk_set from the signal. --- .../content_libraries/signal_handlers.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/signal_handlers.py b/openedx/core/djangoapps/content_libraries/signal_handlers.py index 1d723bea8b23..49d40b27d689 100644 --- a/openedx/core/djangoapps/content_libraries/signal_handlers.py +++ b/openedx/core/djangoapps/content_libraries/signal_handlers.py @@ -20,7 +20,7 @@ LIBRARY_COLLECTION_DELETED, LIBRARY_COLLECTION_UPDATED, ) -from openedx_learning.api.authoring import get_collection_components, get_component, get_components +from openedx_learning.api.authoring import get_component, get_components from openedx_learning.api.authoring_models import Collection, CollectionPublishableEntity, Component, PublishableEntity from lms.djangoapps.grades.api import signals as grades_signals @@ -182,18 +182,12 @@ def library_collection_entities_changed(sender, instance, action, pk_set, **kwar _library_collection_component_changed(instance.component, library.library_key) return + # When action=="post_clear", pk_set==None + # Since the collection instance now has an empty entities set, + # we don't know which ones were removed, so we need to update associations for all library components. + components = get_components(instance.learning_package_id) if pk_set: - components = get_collection_components( - instance.learning_package_id, - instance.key, - ).filter(pk__in=pk_set) - else: - # When action=="post_clear", pk_set==None - # Since the collection instance now has an empty entities set, - # we don't know which ones were removed, so we need to update associations for all library components. - components = get_components( - instance.learning_package_id, - ) + components = components.filter(pk__in=pk_set) for component in components.all(): _library_collection_component_changed(component, library.library_key)