djangogirls icon indicating copy to clipboard operation
djangogirls copied to clipboard

IntegrityError: duplicate key value violates unique constraint "applications_application_form_id_b47c846a_uniq"

Open sentry-io[bot] opened this issue 1 year ago • 1 comments

Sentry Issue: DJANGO-GIRLS-WEBSITE-43

UniqueViolation: duplicate key value violates unique constraint "applications_application_form_id_b47c846a_uniq"
DETAIL:  Key (form_id, email)=(675, ) already exists.

  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

IntegrityError: duplicate key value violates unique constraint "applications_application_form_id_b47c846a_uniq"
DETAIL:  Key (form_id, email)=(675, ) already exists.

(12 additional frame(s) were not displayed)
...
  File "django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

sentry-io[bot] avatar Aug 09 '22 08:08 sentry-io[bot]

def save(self, *args, **kwargs):
    application = Application.objects.create(form=self.form)

This seems to be related to this line, in ApplicationForm we initially create an application for that form_id with no e-mail. Afterwards, we loop through question types and assign an e-mail to the application.

According to code, it looks like there could be forms that don't require e-mails, but I wonder if we accept applications without an e-mail? Maybe instead of calling objects.create we can just instantiate an Application record and save it when we post process the forms questions and answers?

ramonsaraiva avatar Sep 29 '22 17:09 ramonsaraiva