From fce33cd03403d3fd4cf4671ab214f70d4b25f269 Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Fri, 21 Jun 2013 14:15:30 +0000 Subject: [PATCH] Don't crash if an attachment has been created already, just reuse it - this case shouldn't actually happen, but apparently sometimes does, probably due to a concurrency issue - Legacy-Id: 5797 --- ietf/liaisons/formsREDESIGN.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ietf/liaisons/formsREDESIGN.py b/ietf/liaisons/formsREDESIGN.py index b1cadfb76..4cb1b022a 100644 --- a/ietf/liaisons/formsREDESIGN.py +++ b/ietf/liaisons/formsREDESIGN.py @@ -280,11 +280,13 @@ class LiaisonForm(forms.Form): extension = '' written += 1 name = instance.name() + ("-attachment-%s" % written) - attach = Document.objects.create( - title = self.data.get(title_key), - type_id = "liaison", + attach, _ = Document.objects.get_or_create( name = name, - external_url = name + extension, # strictly speaking not necessary, but just for the time being ... + defaults=dict( + title = self.data.get(title_key), + type_id = "liaison", + external_url = name + extension, # strictly speaking not necessary, but just for the time being ... + ) ) instance.attachments.add(attach) attach_file = open(os.path.join(settings.LIAISON_ATTACH_PATH, attach.name + extension), 'w')