File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -307,13 +307,15 @@ def handle_bulk_upload(self, request):
307307 file = self .cleaned_data ['file' ]
308308 delimiter = self .cleaned_data ['field_delimiter' ]
309309 quotechar = self .cleaned_data ['string_delimiter' ]
310- project_import = ProjectImport .objects .create (
311- created_by = request .user ,
312- file = file ,
313- )
314310
315311 try :
312+ project_import = ProjectImport .objects .none () # for later reference, if next command fails
313+ # this should be the first to avoid file.closed state on Azure due to the following command:
316314 projects = self ._handle_bulk_upload (request .user , file , delimiter , quotechar )
315+ project_import = ProjectImport .objects .create (
316+ created_by = request .user ,
317+ file = file ,
318+ )
317319 project_import .projects_created .add (* projects )
318320 project_import .message = f'Successfully added <b>{ len (projects )} </b> project(s) using <b>{ file } </b>.'
319321 project_import .status = ProjectImport .ProjImpStatus .SUCCESS
@@ -330,4 +332,5 @@ def handle_bulk_upload(self, request):
330332 )
331333 messages .add_message (request , messages .ERROR , mark_safe (project_import .message ))
332334 project_import .status = ProjectImport .ProjImpStatus .FAILURE
333- project_import .save ()
335+ if project_import :
336+ project_import .save ()
You can’t perform that action at this time.
0 commit comments