@@ -685,36 +685,37 @@ def _create_block(request):
685685 status = 400 ,
686686 )
687687
688- created_block = create_xblock (
689- parent_locator = parent_locator ,
690- user = request .user ,
691- category = category ,
692- display_name = request .json .get ("display_name" ),
693- boilerplate = request .json .get ("boilerplate" ),
694- )
688+ store = modulestore ()
689+ with store .bulk_operations (usage_key .course_key ):
690+ created_block = create_xblock (
691+ parent_locator = parent_locator ,
692+ user = request .user ,
693+ category = category ,
694+ display_name = request .json .get ("display_name" ),
695+ boilerplate = request .json .get ("boilerplate" ),
696+ )
695697
696- response = {
697- "locator" : str (created_block .location ),
698- "courseKey" : str (created_block .location .course_key ),
699- }
700- # If it contains library_content_key, the block is being imported from a v2 library
701- # so it needs to be synced with upstream block.
702- if upstream_ref := request .json .get ("library_content_key" ):
703- # Set `created_block.upstream` and then sync this with the upstream (library) version.
704- created_block .upstream = upstream_ref
705- try :
706- store = modulestore ()
707- static_file_notices = sync_library_content (created_block , request , store )
708- except BadUpstream as exc :
709- _delete_item (created_block .location , request .user )
710- log .exception (
711- f"Could not sync to new block at '{ created_block .usage_key } ' "
712- f"using provided library_content_key='{ upstream_ref } '"
713- )
714- return JsonResponse ({"error" : str (exc )}, status = 400 )
715- response ["upstreamRef" ] = upstream_ref
716- response ["static_file_notices" ] = asdict (static_file_notices )
717- response ["parent_locator" ] = parent_locator
698+ response = {
699+ "locator" : str (created_block .location ),
700+ "courseKey" : str (created_block .location .course_key ),
701+ }
702+ # If it contains library_content_key, the block is being imported from a v2 library
703+ # so it needs to be synced with upstream block.
704+ if upstream_ref := request .json .get ("library_content_key" ):
705+ # Set `created_block.upstream` and then sync this with the upstream (library) version.
706+ created_block .upstream = upstream_ref
707+ try :
708+ static_file_notices = sync_library_content (created_block , request , store )
709+ except BadUpstream as exc :
710+ _delete_item (created_block .location , request .user )
711+ log .exception (
712+ f"Could not sync to new block at '{ created_block .usage_key } ' "
713+ f"using provided library_content_key='{ upstream_ref } '"
714+ )
715+ return JsonResponse ({"error" : str (exc )}, status = 400 )
716+ response ["upstreamRef" ] = upstream_ref
717+ response ["static_file_notices" ] = asdict (static_file_notices )
718+ response ["parent_locator" ] = parent_locator
718719
719720 return JsonResponse (response )
720721
0 commit comments