Skip to content

Commit 7a1feba

Browse files
committed
Fix bug where new project w new pi started complaining about non-existing pi
1 parent e719cc7 commit 7a1feba

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/backend/datasets/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,18 @@ def save_new_project(request):
723723
elif data['ptype_id'] == settings.LOCAL_PTYPE_ID:
724724
# FIXME set internal PI in conf/settings maybe
725725
pi_id = INTERNAL_PI_PK
726-
else:
726+
elif not (newpiname := data.get('newpiname', False)):
727727
try:
728728
pi_id = int(data['pi_id'])
729729
except ValueError:
730730
return JsonResponse({'error': 'Please select a PI'}, status=403)
731+
else:
732+
# This runs if newpiname, for linter, it will complain if not having this
733+
pi_id = False
731734

732735
if models.Project.objects.filter(name=data['name']):
733736
return JsonResponse({'error': 'Project name already exists'}, status=403)
734-
if 'newpiname' in data:
737+
if newpiname:
735738
pi_id = models.PrincipalInvestigator.objects.create(name=data['newpiname']).pk
736739
project = models.Project.objects.create(name=data['name'], pi_id=pi_id,
737740
ptype_id=data['ptype_id'], externalref=data['extref'])

0 commit comments

Comments
 (0)