@@ -634,36 +634,37 @@ def _create_block(request):
634634 status = 400 ,
635635 )
636636
637- created_block = create_xblock (
638- parent_locator = parent_locator ,
639- user = request .user ,
640- category = category ,
641- display_name = request .json .get ("display_name" ),
642- boilerplate = request .json .get ("boilerplate" ),
643- )
637+ store = modulestore ()
638+ with store .bulk_operations (usage_key .course_key ):
639+ created_block = create_xblock (
640+ parent_locator = parent_locator ,
641+ user = request .user ,
642+ category = category ,
643+ display_name = request .json .get ("display_name" ),
644+ boilerplate = request .json .get ("boilerplate" ),
645+ )
644646
645- response = {
646- "locator" : str (created_block .location ),
647- "courseKey" : str (created_block .location .course_key ),
648- }
649- # If it contains library_content_key, the block is being imported from a v2 library
650- # so it needs to be synced with upstream block.
651- if upstream_ref := request .json .get ("library_content_key" ):
652- # Set `created_block.upstream` and then sync this with the upstream (library) version.
653- created_block .upstream = upstream_ref
654- try :
655- store = modulestore ()
656- static_file_notices = sync_library_content (created_block , request , store )
657- except BadUpstream as exc :
658- _delete_item (created_block .location , request .user )
659- log .exception (
660- f"Could not sync to new block at '{ created_block .usage_key } ' "
661- f"using provided library_content_key='{ upstream_ref } '"
662- )
663- return JsonResponse ({"error" : str (exc )}, status = 400 )
664- response ["upstreamRef" ] = upstream_ref
665- response ["static_file_notices" ] = asdict (static_file_notices )
666- response ["parent_locator" ] = parent_locator
647+ response = {
648+ "locator" : str (created_block .location ),
649+ "courseKey" : str (created_block .location .course_key ),
650+ }
651+ # If it contains library_content_key, the block is being imported from a v2 library
652+ # so it needs to be synced with upstream block.
653+ if upstream_ref := request .json .get ("library_content_key" ):
654+ # Set `created_block.upstream` and then sync this with the upstream (library) version.
655+ created_block .upstream = upstream_ref
656+ try :
657+ static_file_notices = sync_library_content (created_block , request , store )
658+ except BadUpstream as exc :
659+ _delete_item (created_block .location , request .user )
660+ log .exception (
661+ f"Could not sync to new block at '{ created_block .usage_key } ' "
662+ f"using provided library_content_key='{ upstream_ref } '"
663+ )
664+ return JsonResponse ({"error" : str (exc )}, status = 400 )
665+ response ["upstreamRef" ] = upstream_ref
666+ response ["static_file_notices" ] = asdict (static_file_notices )
667+ response ["parent_locator" ] = parent_locator
667668
668669 return JsonResponse (response )
669670
0 commit comments