Skip to content

Commit

Permalink
fix: use get_components in m2m_changed signal handler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
navinkarkera committed Oct 11, 2024
1 parent 51bab0d commit 4409ddc
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions openedx/core/djangoapps/content_libraries/signal_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 4409ddc

Please sign in to comment.