Skip to content

Commit 11d1856

Browse files
committed
fix: PR review comments
1 parent cf7f6d0 commit 11d1856

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/openedx_tagging/signal_handlers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Signal handlers for tagging-related model updates."""
22

3+
from functools import partial
4+
35
from django.db import transaction
46
from django.db.models.signals import post_save
57
from django.dispatch import receiver
@@ -23,5 +25,8 @@ def tag_post_save(sender, **kwargs): # pylint: disable=unused-argument
2325
return
2426

2527
transaction.on_commit(
26-
lambda: emit_content_object_associations_changed_for_tag_task.delay(tag_id)
28+
partial(
29+
emit_content_object_associations_changed_for_tag_task.delay,
30+
tag_id=tag_id
31+
)
2732
)

src/openedx_tagging/tasks.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313

1414
def _emit_content_object_associations_changed_for_tag(tag: Tag) -> int:
15-
"""Emit CONTENT_OBJECT_ASSOCIATIONS_CHANGED for each object associated with the given tag."""
15+
"""
16+
Emit CONTENT_OBJECT_ASSOCIATIONS_CHANGED events for each content object linked to this tag
17+
via the ObjectTag assciations. This is used to trigger downstream updates
18+
like search index refreshes in Meilisearch.
19+
"""
1620
object_ids = ObjectTag.objects.filter(tag=tag).values_list("object_id", flat=True)
1721
emitted_events = 0
1822

@@ -37,7 +41,12 @@ def _emit_content_object_associations_changed_for_tag(tag: Tag) -> int:
3741

3842
@shared_task
3943
def emit_content_object_associations_changed_for_tag_task(tag_id: int) -> int:
40-
"""Emit content association changed events for all objects linked to the given tag id."""
44+
"""
45+
When a tag is updated, emit a CONTENT_OBJECT_ASSOCIATIONS_CHANGED event for every ObjectTag linked to that tag.
46+
Each ObjectTag represents an association between the tag and an Open edX object.
47+
Because downstream systems (for example, search indexes such as Meilisearch) index object-tag relationships,
48+
they must be notified so they can refresh the object's association data.
49+
"""
4150
try:
4251
tag = Tag.objects.get(pk=tag_id)
4352
except Tag.DoesNotExist:

tests/openedx_tagging/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ def test_rename_updates_search_index(self, mock_task_delay) -> None:
11541154
self.alice.save()
11551155

11561156
assert mock_task_delay.call_count == 1
1157-
assert mock_task_delay.call_args[0][0] == self.alice.id
1157+
assert mock_task_delay.call_args[1]['tag_id'] == self.alice.id
11581158

11591159
@patch("openedx_tagging.tasks.CONTENT_OBJECT_ASSOCIATIONS_CHANGED", new_callable=MagicMock)
11601160
def test_emit_content_object_associations_changed_for_tag_task(self, mock_signal) -> None:

0 commit comments

Comments
 (0)