catch error when the wish really existed.

pull/94/head
eric 2020-08-06 14:05:02 -04:00
parent b565371c0a
commit aa79924824
1 changed files with 7 additions and 3 deletions

View File

@ -22,11 +22,11 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.fields import GenericRelation
from django.urls import reverse
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.db import models from django.db import models, IntegrityError
from django.db.models import F, Q from django.db.models import F, Q
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.urls import reverse
from django.utils.timezone import now from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -1077,7 +1077,11 @@ class Wishlist(models.Model):
try: try:
w = Wishes.objects.get(wishlist=self, work=work) w = Wishes.objects.get(wishlist=self, work=work)
except Wishes.DoesNotExist: except Wishes.DoesNotExist:
Wishes.objects.create(source=source, wishlist=self, work=work) try:
Wishes.objects.create(source=source, wishlist=self, work=work)
except IntegrityError:
# threading issue?
return
work.update_num_wishes() work.update_num_wishes()
# only send notification in case of new wishes # only send notification in case of new wishes
# and only when they result from user action, not (e.g.) our tests # and only when they result from user action, not (e.g.) our tests