Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix: index sometimes not updating when xblock updates #34754

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
################################# CELERY ######################################

# By default don't use a worker, execute tasks as if they were local functions
CELERY_ALWAYS_EAGER = True
CELERY_ALWAYS_EAGER = False

# When the celery task is eagerly, it is executed locally while sharing the
# thread and its request cache with the active Django Request. In that case,
# do not clear the cache.
CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION = False
CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION = True

################################ DEBUG TOOLBAR ################################

Expand Down
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/content/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ def upsert_xblock_index_doc(usage_key: UsageKey, recursive: bool = True) -> None
if xblock_type in EXCLUDED_XBLOCK_TYPES:
return

print("\n\n\n\n\n ========== the actual xblock", xblock)

docs = []

def add_with_children(block):
Expand Down
6 changes: 6 additions & 0 deletions openedx/core/djangoapps/content/search/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def xblock_updated_handler(**kwargs) -> None:
Update the index for the XBlock and its children
"""
xblock_info = kwargs.get("xblock_info", None)
print("\n\n\n\n\n\n================= xblock_info", xblock_info)

from xmodule.modulestore.django import modulestore
_xblock = modulestore().get_item(xblock_info.usage_key)
print("\n\n\n\n\n ======== xblock before sending to celery", _xblock, "\n")

if not xblock_info or not isinstance(xblock_info, XBlockData): # pragma: no cover
log.error("Received null or incorrect data for event")
return
Expand Down
26 changes: 16 additions & 10 deletions xmodule/modulestore/mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)

from django.utils.timezone import datetime, timezone
from django.db import transaction
from xmodule.assetstore import AssetMetadata

from . import XMODULE_FIELDS_WITH_USAGE_KEYS, ModuleStoreWriteBase
Expand Down Expand Up @@ -828,17 +829,22 @@ def update_item(self, xblock, user_id, allow_not_found=False, **kwargs): # lint
Update the xblock persisted to be the same as the given for all types of fields
(content, children, and metadata) attribute the change to the given user.
"""
store = self._verify_modulestore_support(xblock.location.course_key, 'update_item')
xblock = store.update_item(xblock, user_id, allow_not_found, **kwargs)
# .. event_implemented_name: XBLOCK_UPDATED
XBLOCK_UPDATED.send_event(
time=datetime.now(timezone.utc),
xblock_info=XBlockData(
usage_key=xblock.location.for_branch(None),
block_type=xblock.location.block_type,
version=xblock.location

with transaction.atomic():
store = self._verify_modulestore_support(xblock.location.course_key, 'update_item')
xblock = store.update_item(xblock, user_id, allow_not_found, **kwargs)
transaction.on_commit(lambda:
# .. event_implemented_name: XBLOCK_UPDATED
XBLOCK_UPDATED.send_event(
time=datetime.now(timezone.utc),
xblock_info=XBlockData(
usage_key=xblock.location.for_branch(None),
block_type=xblock.location.block_type,
version=xblock.location
)
)
)
)

return xblock

@strip_key
Expand Down
Loading