diff --git a/cms/envs/devstack.py b/cms/envs/devstack.py index 3fe10377d79c..fa8d233fb0f8 100644 --- a/cms/envs/devstack.py +++ b/cms/envs/devstack.py @@ -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 ################################ diff --git a/openedx/core/djangoapps/content/search/api.py b/openedx/core/djangoapps/content/search/api.py index bbde4fc98230..b179129693f7 100644 --- a/openedx/core/djangoapps/content/search/api.py +++ b/openedx/core/djangoapps/content/search/api.py @@ -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): diff --git a/openedx/core/djangoapps/content/search/handlers.py b/openedx/core/djangoapps/content/search/handlers.py index 1a80b2215781..2e1ac064d7e9 100644 --- a/openedx/core/djangoapps/content/search/handlers.py +++ b/openedx/core/djangoapps/content/search/handlers.py @@ -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 diff --git a/xmodule/modulestore/mixed.py b/xmodule/modulestore/mixed.py index 9665772d2718..f7042121c251 100644 --- a/xmodule/modulestore/mixed.py +++ b/xmodule/modulestore/mixed.py @@ -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 @@ -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