-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: Update on_commit_changes_to of modulestore to check MySQL transaction [FC-0097]
#37485
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
fix: Update on_commit_changes_to of modulestore to check MySQL transaction [FC-0097]
#37485
Conversation
`handle_update_xblock_upstream_link` is called asynchronously with celery. In `update_upstream_downstream_link_handler`, the xblock has the updated version, but when calling `handle_update_xblock_upstream_link` inside Celry, the xblock is outdated in a previous version, that is why the error occurs. The immediate fix is to call handle_update_xblock_upstream_link synchronously.
|
Thanks for the pull request, @ChrisChV! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
@navinkarkera @bradenmacdonald The error occurs because Celery is getting an outdated version of the xblock in handle_update_xblock_upstream_link. I think it's more due to a cache error or something like that. It shouldn't be a race condition with the xblock update (or maybe a very rare one), because I got the xblock in update_upstream_downstream_link_handler, and it is the updated version. |
|
@ChrisChV The Maybe something like this would help? +from django.db import transaction
...
def on_commit_changes_to(self, course_key, fn):
"""
Call some callback when the currently active bulk operation has saved
"""
+ # If we're in a MySQL transaction, so the new version will only be committed to the
+ # SplitModulestoreCourseIndex table after the MySQL transaction is closed.
+ def wrapped_fn():
+ transaction.on_commit(fn)
# Check if a bulk op is active. If so, defer fn(); otherwise call it immediately.
# Note: calling _get_bulk_ops_record() here and then checking .active can have side-effects in some cases
# because it creates an entry in the defaultdict if none exists, so we check if the record is active using
# the same code as _clear_bulk_ops_record(), which doesn't modify the defaultdict.
# so we check it this way:
if course_key and course_key.for_branch(None) in self._active_bulk_ops.records:
bulk_ops_record = self._active_bulk_ops.records[course_key.for_branch(None)]
- bulk_ops_record.defer_until_commit(fn)
+ bulk_ops_record.defer_until_commit(wrapped_fn)
else:
- fn() # There is no active bulk operation - call fn() now.
+ wrapped_fn() # There is no active bulk operation - call fn() now. |
|
@ChrisChV @bradenmacdonald Do we have a case where we are not in a mysql transaction? |
|
@ChrisChV Did that change help at all? @navinkarkera It's possible to be in autocommit mode, with only implicit transactions, yes. But this code should still work fine, just trigger the event immediately in that case. |
Yes, it worked. But I need to get it ready to pass some tests. Using the last change, there are tests that show that the function passed to |
So that really shouldn't be necessary. Maybe it's one of these other things the docs mention?
Or maybe this would help debug?
|
|
@bradenmacdonald This is the issue (ref):
I have two options. Change each failed test so that it actually calls |
|
@ChrisChV Yep, either of those sounds fine to me. |
navinkarkera
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChrisChV Looks good 👍
- I tested this: (Verified that the bug is fixed in sandbox)
- I read through the code
- I checked for accessibility issues
- Includes documentation
on_commit_changes_to of modulestore to check MySQL transaction [FC-0097]
…saction [FC-0097] (openedx#37485) - `handle_update_xblock_upstream_link` is called asynchronously with celery. In `update_upstream_downstream_link_handler`, the xblock has the updated version, but when calling `handle_update_xblock_upstream_link` inside Celery, the xblock is outdated in a previous version, which is why the error occurs. This happens because `on_commit_changes_to` is executed before the MySQL transaction ends. - Added `ImmediateOnCommitMixin` to be used in tests that need to call `on_commit_changes_to`. See openedx#37485 (comment) for more info
…saction [FC-0097] (openedx#37485) - `handle_update_xblock_upstream_link` is called asynchronously with celery. In `update_upstream_downstream_link_handler`, the xblock has the updated version, but when calling `handle_update_xblock_upstream_link` inside Celery, the xblock is outdated in a previous version, which is why the error occurs. This happens because `on_commit_changes_to` is executed before the MySQL transaction ends. - Added `ImmediateOnCommitMixin` to be used in tests that need to call `on_commit_changes_to`. See openedx#37485 (comment) for more info
Description
Fixes the error described in openedx/frontend-app-authoring#1977 (comment)
handle_update_xblock_upstream_linkis called asynchronously with celery. Inupdate_upstream_downstream_link_handler, the xblock has the updated version, but when callinghandle_update_xblock_upstream_linkinside Celery, the xblock is outdated in a previous version, which is why the error occurs. This happens becauseon_commit_changes_tois executed before the MySQL transaction ends.ImmediateOnCommitMixinto be used in tests that need to callon_commit_changes_to. See fix: Updateon_commit_changes_toof modulestore to check MySQL transaction [FC-0097] #37485 (comment) for more infoSupporting information
Github issue: openedx/frontend-app-authoring#2484 (comment)
Internal ticket: FAL-4258
Testing instructions
Deadline
ASAP, before the Ulmo cut
Other information
N/A