Skip to content

Commit 891b473

Browse files
authored
fix(contentstore): guard downstream_customized copy on paste (#38457)
Fix clipboard paste crash in upstream-link setup when pasted block does not expose `xml_attributes`. Before change, paste flow always read `temp_xblock.xml_attributes["downstream_customized"]`. Blocks like `DragAndDropBlockWithMixins` do not have `xml_attributes`, so Studio raised `AttributeError` and paste failed. Change now: - Read `downstream_customized` from parsed block field first (`getattr(temp_xblock, "downstream_customized", [])`). - Read `xml_attributes` only when block exposes it. - Set `downstream_customized` only when block has field.
1 parent e4f07e3 commit 891b473

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

cms/djangoapps/contentstore/helpers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,18 @@ def _fetch_and_set_upstream_link(
509509
# temp_xblock.display_name == temp_xblock.upstream_display_name
510510
# temp_xblock.data == temp_xblock.upstream_data # for html blocks
511511
# Even then we want to set `downstream_customized` value to avoid overriding user customisations on sync
512-
downstream_customized = temp_xblock.xml_attributes.get("downstream_customized", '[]')
513-
temp_xblock.downstream_customized = json.loads(downstream_customized)
512+
downstream_customized = getattr(temp_xblock, "downstream_customized", [])
513+
# XmlMixin blocks expose raw XML attrs on `xml_attributes`; other blocks (e.g. DnD)
514+
# may not have this attribute, but still have parsed downstream_customized field.
515+
xml_attributes = getattr(temp_xblock, "xml_attributes", None)
516+
if isinstance(xml_attributes, dict):
517+
raw_downstream_customized = xml_attributes.get("downstream_customized")
518+
if isinstance(raw_downstream_customized, str):
519+
downstream_customized = json.loads(raw_downstream_customized)
520+
elif isinstance(raw_downstream_customized, list):
521+
downstream_customized = raw_downstream_customized
522+
if hasattr(temp_xblock, "downstream_customized"):
523+
temp_xblock.downstream_customized = downstream_customized
514524

515525

516526
def _import_xml_node_to_parent(

0 commit comments

Comments
 (0)