@@ -1062,7 +1062,10 @@ def parse_mail(mail, list_id=None):
filenames = find_filenames(diff)
delegate = find_delegate_by_filename(project, filenames)
- try:
+ with transaction.atomic():
+ if Patch.objects.filter(project=project, msgid=msgid):
+ raise DuplicateMailError(msgid=msgid)
+
patch = Patch.objects.create(
msgid=msgid,
project=project,
@@ -1077,8 +1080,6 @@ def parse_mail(mail, list_id=None):
delegate=delegate,
state=find_state(mail))
logger.debug('Patch saved')
- except IntegrityError:
- raise DuplicateMailError(msgid=msgid)
for attempt in range(1, 11): # arbitrary retry count
try:
Currently, the parser relies on causing (and catching) IntegrityErrors on patch insert to catch duplicate (msgid,project) mails. This change performs an atomic select -> insert instead. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> --- patchwork/parser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)