Skip to content

Commit

Permalink
Fix candidates being registered twice by an organization
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Nov 17, 2024
1 parent b2d6eb9 commit d0e76d0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion backend/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,19 @@ def post(self, request, *args, **kwargs):
if check_result:
return check_result

return super().post(request, *args, **kwargs)
try:
return super().post(request, *args, **kwargs)
except IntegrityError as exc:
if "hub_candidate_org_id_key" in str(exc):
existing_candidate_pk = request.user.organization.candidate.pk
logger.info(
f"User {request.user} tried to create a new candidate when one already exists. "
f"Redirecting to existing candidate {existing_candidate_pk}."
)

return redirect(reverse("candidate-update", args=(existing_candidate_pk,)))

raise exc

def get_form_kwargs(self):
kwargs = super(CandidateRegisterRequestCreateView, self).get_form_kwargs()
Expand Down

0 comments on commit d0e76d0

Please sign in to comment.