Skip to content

Conversation

@navinkarkera
Copy link
Contributor

@navinkarkera navinkarkera commented Oct 30, 2025

Description

The child.save() call while migrating legacy library block to library version 2 fails with InvalidScopeError due to presence of LmsFieldData in _bound_field_data field.
Removing this call does not seem to have any adverse affect.

Error log:

Traceback (most recent call last):
  File "/openedx/edx-platform/cms/djangoapps/contentstore/views/preview.py", line 77, in preview_handler
    resp = instance.handle(handler, req, suffix)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/xblock/core.py", line 483, in handle
    return self.runtime.handle(self, handler_name, request, suffix)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/edx-platform/xmodule/x_module.py", line 1008, in handle
    return super().handle(block, handler_name, request, suffix=suffix)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/xblock/runtime.py", line 1057, in handle
    results = handler(request, suffix)
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/edx-platform/xmodule/library_content_block.py", line 401, in upgrade_to_v2_library
    self._v2_update_children_upstream_version()
  File "/openedx/edx-platform/xmodule/library_content_block.py", line 329, in _v2_update_children_upstream_version
    child.save()
  File "/openedx/venv/lib/python3.11/site-packages/xblock/core.py", line 514, in save
    self.force_save_fields(fields_to_save)
  File "/openedx/venv/lib/python3.11/site-packages/xblock/core.py", line 531, in force_save_fields
    self._field_data.set_many(self, fields_to_save_json)
  File "/openedx/venv/lib/python3.11/site-packages/xblock/field_data.py", line 166, in set_many
    field_data.set_many(block, new_update_dict)
  File "/openedx/venv/lib/python3.11/site-packages/xblock/field_data.py", line 88, in set_many
    self.set(block, key, value)
  File "/openedx/venv/lib/python3.11/site-packages/xblock/field_data.py", line 196, in set
    raise InvalidScopeError(f"{block}.{name} is read-only, cannot set")
xblock.exceptions.InvalidScopeError

Child field data:

{'_asides': [], '_cds_init_args': False, '_parent_block': <LegacyLibraryContentBlockWithMixins @5303 copied_from_block=None, downstream_customized=[], top_level_downstream_parent_key=None, upstream=None, upstream_display_name=None, upstream_version=None, upstream_version_declined=None, name=None, parent=BlockUsageLocator(CourseLocator('SampleTaxonomyOrg1', 'Chris456', 'chris456', None, None), 'vertical', 'd6b6fc5fd9104961aa83406773ddeea9'), tags=[], display_name='Randomized Content Block', course_edit_method='Studio', days_early_for_beta=None, due=None, edxnotes=False, edxnotes_visibility=True, giturl=None, graceperiod=None, graded=False, group_access={}, hide_from_toc=False, in_entrance_exam=False, matlab_api_key=None, max_attempts=None, relative_weeks_due=None, rerandomize='never', self_paced=False, show_correctness='always', show_reset_button=False, showanswer='finished', start=datetime.datetime(2030, 1, 1, 0, 0, tzinfo=tzlocal()), static_asset_path='', use_latex_compiler=False, user_partitions=[], video_auto_advance=False, video_bumper={}, video_speed_optimizations=True, visible_to_staff_only=False, xqa_key=None, chrome=None, default_tab=None, format=None, source_file=None, allow_resetting_children=False, children=[BlockUsageLocator(CourseLocator('SampleTaxonomyOrg1', 'Chris456', 'chris456', None, None), 'video', '4efeb593d14c61314395')], max_count=1, selected=[], xml_attributes={}, capa_type='any', is_migrated_to_v2=False, source_library_id='library-v1:tlmigration+tl123', source_library_version='68dc402f7ef716eebf702cf0'>, '_parent_block_id': BlockUsageLocator(CourseLocator('SampleTaxonomyOrg1', 'Chris456', 'chris456', None, None), 'library_content', '69629111a73b4504a0467511696a42ef'), '_child_cache': {}, '_runtime': <xmodule.modulestore.split_mongo.runtime.SplitModuleStoreRuntime object at 0x7f69e3bc34d0>, '_deprecated_per_instance_field_data': None, '_field_data_cache': {'upstream': 'lb:OpenCraft:chrislibrary:video:2cd6ffa4549b40ea8eb0521f9d34c3a8', 'upstream_version': 0}, '_dirty_fields': {<String upstream>: fields.EXPLICITLY_SET, <Integer upstream_version>: fields.EXPLICITLY_SET}, 'scope_ids': ScopeIds(user_id=40, block_type='video', def_id=ObjectId('68dc402f7ef716eebf702cef'), usage_id=BlockUsageLocator(CourseLocator('SampleTaxonomyOrg1', 'Chris456', 'chris456', None, None), 'video', '4efeb593d14c61314395')), '_edited_by': 40, '_edited_on': datetime.datetime(2025, 10, 30, 5, 51, 54, 319000, tzinfo=<bson.tz_util.FixedOffset object at 0x7f69e3bcdc50>), 'previous_version': None, 'update_version': ObjectId('6902fcfab505035c80dbd175'), 'source_version': None, 'definition_locator': DefinitionLocator(ObjectId('68dc402f7ef716eebf702cef'), 'video'), 'course_version': ObjectId('6902fcfab505035c80dbd175'), '_bound_field_data': LmsFieldData(ReadOnlyFieldData(InheritingFieldData(<xmodule.modulestore.split_mongo.split_mongo_kvs.SplitMongoKVS object at 0x7f69e3c2f010>)), KvsFieldData(<cms.djangoapps.contentstore.views.session_kv_store.SessionKeyValueStore object at 0x7f69e3c2c390>))}

Supporting information

Deadline

Before ULMO Cut off

Other information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.
  • If your database migration can't be rolled back easily.

@openedx-webhooks
Copy link

Thanks for the pull request, @navinkarkera!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Oct 30, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Oct 30, 2025
@navinkarkera
Copy link
Contributor Author

@kdmccormick @bradenmacdonald We noticed this issue in the sandbox. I am not sure if save() is even required as we are calling store.update_item to save the changes.

cc: @ChrisChV

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, but I'll take your word that you've tested that this still properly updates the upstream_version of the source block.

You weren't accidentally triggering this code from the LMS, were you? I'm not sure why you would be, but that's the only logical reason I could think of for .save() to cause this exception (of course, given how messy xblock field data APIs are, there are plenty of illogical reasons for .save() to cause this exception...)

Comment on lines 328 to 330
# Save fails with InvalidScopeError due to `_bound_field_data` field containing LmsFieldData which
# is ready-only. This was only seen in production instance and not observed in local dev instance.
# child.save()
Copy link
Member

@kdmccormick kdmccormick Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Save fails with InvalidScopeError due to `_bound_field_data` field containing LmsFieldData which
# is ready-only. This was only seen in production instance and not observed in local dev instance.
# child.save()
# Save fails with InvalidScopeError due to `_bound_field_data` field containing LmsFieldData which
# is ready-only. This was only seen in production instance and not observed in local dev instance.
# child.save()

Unless you hope to reinstate child.save(), there's no reason to leave a comment on dead code. Just remove it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense.

Copy link
Contributor Author

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You weren't accidentally triggering this code from the LMS, were you?

Nope, there is no option to trigger it in lms. It is really weird.

Comment on lines 328 to 330
# Save fails with InvalidScopeError due to `_bound_field_data` field containing LmsFieldData which
# is ready-only. This was only seen in production instance and not observed in local dev instance.
# child.save()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense.

@navinkarkera navinkarkera enabled auto-merge (squash) October 30, 2025 14:31
@navinkarkera navinkarkera merged commit 72dac75 into openedx:master Oct 30, 2025
48 checks passed
@navinkarkera navinkarkera deleted the navin/fix-save-issue branch October 30, 2025 14:53
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in Contributions Oct 30, 2025
haftamuk pushed a commit to haftamuk/edx-platform that referenced this pull request Nov 3, 2025
…le migrating (openedx#37573)

The child.save() call while migrating legacy library block to library version 2 fails with `InvalidScopeError` due to presence of `LmsFieldData` in` _bound_field_data` field. Removing this call does not seem to have any adverse affect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants