Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntegrityError: duplicate key value violates unique constraint "unique_form_email_email_not_null" #901

Open
sentry-io bot opened this issue Jul 14, 2023 · 6 comments

Comments

@sentry-io
Copy link

sentry-io bot commented Jul 14, 2023

Sentry Issue: DJANGO-GIRLS-WEBSITE-5H

UniqueViolation: duplicate key value violates unique constraint "unique_form_email_email_not_null"
DETAIL:  Key (form_id, email)=(790, [email protected]) 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 "unique_form_email_email_not_null"
DETAIL:  Key (form_id, email)=(790, [email protected]) already exists.

(12 additional frame(s) were not displayed)
...
  File "applications/views.py", line 41, in apply
    form.save()
  File "applications/forms.py", line 121, in save
    application.save()
  File "applications/models.py", line 166, in save
    super().save(*args, **kwargs)
@amakarudze
Copy link
Contributor

Hey @anaschwendler, do you think you can pick this one up? I can help if you need my assistance. Thanks!

@anaschwendler
Copy link
Contributor

Yup, I'll take a look on it tomorrow :)

@anaschwendler
Copy link
Contributor

@amakarudze

I'm reading the error here, and I would like to know which approach I should take. Should I remove this or maybe return the form filled with the information?

Thank you!

@amakarudze
Copy link
Contributor

Hello @anaschwendler, no you should not remove that. That's just the name of the UniqueConstraint we have for the email and form to ensure that an applicant can only apply once for an event and that is set up correctly. See https://docs.djangoproject.com/en/4.2/ref/models/constraints/#uniqueconstraint.

What we could do is change the way we save the application in our view here when we save the form so that we can catch the exception and let the user know that the email address has already been used to apply for that event before using a try...except block.

The form.save() and messages.success(...) can be in the try block and then under except IntegrityError, you put messages.error(request, f"Application with email address {email} already exists for this event.").

@MariaMozgunova
Copy link

Hi!
I am new to Django Girls and I want to help by contributing.
Can I help out with this issue?

@amakarudze
Copy link
Contributor

Hey @MariaMozgunova, yes sure feel free to pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants