@@ -801,36 +801,37 @@ def _create_block(request):
801801 status = 400 ,
802802 )
803803
804- created_block = create_xblock (
805- parent_locator = parent_locator ,
806- user = request .user ,
807- category = category ,
808- display_name = request .json .get ("display_name" ),
809- boilerplate = request .json .get ("boilerplate" ),
810- )
804+ store = modulestore ()
805+ with store .bulk_operations (usage_key .course_key ):
806+ created_block = create_xblock (
807+ parent_locator = parent_locator ,
808+ user = request .user ,
809+ category = category ,
810+ display_name = request .json .get ("display_name" ),
811+ boilerplate = request .json .get ("boilerplate" ),
812+ )
811813
812- response = {
813- "locator" : str (created_block .location ),
814- "courseKey" : str (created_block .location .course_key ),
815- }
816- # If it contains library_content_key, the block is being imported from a v2 library
817- # so it needs to be synced with upstream block.
818- if upstream_ref := request .json .get ("library_content_key" ):
819- # Set `created_block.upstream` and then sync this with the upstream (library) version.
820- created_block .upstream = upstream_ref
821- try :
822- store = modulestore ()
823- static_file_notices = sync_library_content (created_block , request , store )
824- except BadUpstream as exc :
825- _delete_item (created_block .location , request .user )
826- log .exception (
827- f"Could not sync to new block at '{ created_block .usage_key } ' "
828- f"using provided library_content_key='{ upstream_ref } '"
829- )
830- return JsonResponse ({"error" : str (exc )}, status = 400 )
831- response ["upstreamRef" ] = upstream_ref
832- response ["static_file_notices" ] = asdict (static_file_notices )
833- response ["parent_locator" ] = parent_locator
814+ response = {
815+ "locator" : str (created_block .location ),
816+ "courseKey" : str (created_block .location .course_key ),
817+ }
818+ # If it contains library_content_key, the block is being imported from a v2 library
819+ # so it needs to be synced with upstream block.
820+ if upstream_ref := request .json .get ("library_content_key" ):
821+ # Set `created_block.upstream` and then sync this with the upstream (library) version.
822+ created_block .upstream = upstream_ref
823+ try :
824+ static_file_notices = sync_library_content (created_block , request , store )
825+ except BadUpstream as exc :
826+ _delete_item (created_block .location , request .user )
827+ log .exception (
828+ f"Could not sync to new block at '{ created_block .usage_key } ' "
829+ f"using provided library_content_key='{ upstream_ref } '"
830+ )
831+ return JsonResponse ({"error" : str (exc )}, status = 400 )
832+ response ["upstreamRef" ] = upstream_ref
833+ response ["static_file_notices" ] = asdict (static_file_notices )
834+ response ["parent_locator" ] = parent_locator
834835
835836 return JsonResponse (response )
836837
0 commit comments