Skip to content

Commit

Permalink
Some defensive programming that has been mandated by new pylint versi…
Browse files Browse the repository at this point in the history
…on (which is unsure if variables are set)
  • Loading branch information
glormph committed May 30, 2024
1 parent 86e9342 commit d92643e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/backend/analysis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ def start_analysis(request):
return JsonResponse({'error': 'Must use POST'}, status=405)
req = json.loads(request.body.decode('utf-8'))
try:
job = False
if 'item_id' in req:
# home app
job = jm.Job.objects.get(nextflowsearch__id=req['item_id'])
Expand All @@ -1139,6 +1140,8 @@ def start_analysis(request):
job = jm.Job.objects.get(nextflowsearch__analysis_id=req['analysis_id'])
except jm.Job.DoesNotExist:
return JsonResponse({'error': 'This job does not exist (anymore), it may have been deleted'}, status=403)
if not job:
return JsonResponse({'error': 'This job does not exist (anymore), it may have been deleted'}, status=403)
ownership = jv.get_job_ownership(job, request)
if not ownership['owner_loggedin'] and not ownership['is_staff']:
return JsonResponse({'error': 'Only job owners and admin can start this job'}, status=403)
Expand Down
3 changes: 3 additions & 0 deletions src/backend/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ def fetch_dset_details(dset):
mzmlfile__sfile__rawfile__datasetrawfile__dataset=dset,
mzmlfile__sfile__deleted=False, mzmlfile__sfile__checked=True), 'existing')
for pwsid, pws in pw_sets.items():
state = False
pwpk, refined = pwsid.split('_')
refined = refined == 'True'
if (not refined and pws['id'] in info['convert_dataset_mzml']) or (refined and pws['id'] in info['refine_mzmls']):
Expand All @@ -834,6 +835,8 @@ def fetch_dset_details(dset):
state = 'Incomplete'
elif refined:
state = 'No mzmls'
if not state:
raise RuntimeError('Something went wrong getting mzMLs')
pws['state'] = state
info['pwiz_sets'] = [x for x in pw_sets.values()]
info['pwiz_versions'] = {x.id: x.version_description for x in anmodels.Proteowizard.objects.exclude(
Expand Down
7 changes: 6 additions & 1 deletion src/backend/jobs/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

def update_db(url, form=False, json=False, files=False, msg=False):
try:
r = False
if form:
r = requests.post(url=url, data=form)
elif json:
Expand All @@ -26,7 +27,11 @@ def update_db(url, form=False, json=False, files=False, msg=False):
print(msg)
raise RuntimeError(msg)
else:
return r
if r:
return r
else:
raise RuntimeError('Something went wrong')



def task_finished(task_id):
Expand Down

0 comments on commit d92643e

Please sign in to comment.