Skip to content

Commit ca664c4

Browse files
authored
fix: don't create a volunteer object when a person has already volunt… (ietf-tools#6809)
* fix: don't create a volunteer object when a person has already volunteered * fix: safer create * refactor: use shorthand from django * fix: also protect volunteer from datatracker from race
1 parent 661e11f commit ca664c4

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

ietf/api/views.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,14 @@ def err(code, text):
210210
except (NomCom.DoesNotExist, NomCom.MultipleObjectsReturned):
211211
nomcom = None
212212
if nomcom:
213-
Volunteer.objects.create(
213+
Volunteer.objects.get_or_create(
214214
nomcom=nomcom,
215215
person=object.person,
216-
affiliation=data['affiliation'],
217-
origin='registration')
216+
defaults={
217+
"affiliation": data["affiliation"],
218+
"origin": "registration"
219+
}
220+
)
218221
return HttpResponse(response, status=202, content_type='text/plain')
219222
else:
220223
return HttpResponse(status=405)

ietf/nomcom/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ def volunteer(request):
13731373
form = VolunteerForm(person=person, data=request.POST)
13741374
if form.is_valid():
13751375
for nc in form.cleaned_data['nomcoms']:
1376-
nc.volunteer_set.create(person=person, affiliation=form.cleaned_data['affiliation'])
1376+
nc.volunteer_set.get_or_create(person=person, defaults={"affiliation": form.cleaned_data["affiliation"], "origin":"datatracker"})
13771377
return redirect('ietf.ietfauth.views.profile')
13781378
else:
13791379
form = VolunteerForm(person=person,initial=dict(nomcoms=can_volunteer, affiliation=suggest_affiliation(person)))

0 commit comments

Comments
 (0)