djangogirls
djangogirls copied to clipboard
IntegrityError: duplicate key value violates unique constraint "unique_form_email_email_not_null"
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)
Hey @anaschwendler, do you think you can pick this one up? I can help if you need my assistance. Thanks!
Yup, I'll take a look on it tomorrow :)
@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!
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.")
.
Hi! I am new to Django Girls and I want to help by contributing. Can I help out with this issue?
Hey @MariaMozgunova, yes sure feel free to pick it up.