summaryrefslogtreecommitdiffstats
path: root/patchwork
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-06-05 14:33:13 +0800
committerJeremy Kerr <jk@ozlabs.org>2015-06-05 14:37:48 +0800
commit41d5ceb82b5d4297570b73639517b642fab0c45f (patch)
tree87af4cff500d1dcd39be8d3678ec8a81f0fefd35 /patchwork
parent30bb271ca25b9652744c3c17d9bc35cde91c6dc3 (diff)
downloadpatchwork-41d5ceb82b5d4297570b73639517b642fab0c45f.tar.bz2
patchwork-41d5ceb82b5d4297570b73639517b642fab0c45f.tar.xz
patchwork/parser: Adapt for new unsaved-foreign-key behaviour in django 1.8
Django 1.8 no longer supports assignment of unsaved models to ForeignKey fields: File "/home/jk/devel/patchwork/patchwork/tests/test_patchparser.py", line 75, in setUp (self.patch, self.comment) = find_content(self.project, email) File "/home/jk/devel/patchwork/patchwork/bin/parsemail.py", line 231, in find_content headers = mail_headers(mail)) File "/home/jk/devel/patchwork/lib/python/django/db/models/base.py", line 468, in __init__ setattr(self, field.name, rel_obj) File "/home/jk/devel/patchwork/lib/python/django/db/models/fields/related.py", line 668, in __set__ (value, self.field.rel.to._meta.object_name) ValueError: Cannot assign "<Patch: Test Subject>": "Patch" instance isn't saved in the database. Even though we'd be guaranteed to save the patch before the comment, we need to avoid this error. This change defers the assigment of Comment.patch until we know we have a saved Patch instance. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'patchwork')
-rwxr-xr-xpatchwork/bin/parsemail.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index 97189a3..f2b10bd 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -220,15 +220,20 @@ def find_content(project, mail):
date = mail_date(mail), headers = mail_headers(mail))
if commentbuf:
+ # If this is a new patch, we defer setting comment.patch until
+ # patch has been saved by the caller
if patch:
- cpatch = patch
+ comment = Comment(date = mail_date(mail),
+ content = clean_content(commentbuf),
+ headers = mail_headers(mail))
+
else:
cpatch = find_patch_for_comment(project, mail)
if not cpatch:
return (None, None)
- comment = Comment(patch = cpatch, date = mail_date(mail),
- content = clean_content(commentbuf),
- headers = mail_headers(mail))
+ comment = Comment(patch = cpatch, date = mail_date(mail),
+ content = clean_content(commentbuf),
+ headers = mail_headers(mail))
return (patch, comment)
@@ -389,8 +394,7 @@ def parse_mail(mail):
if comment:
if save_required:
author.save()
- # looks like the original constructor for Comment takes the pk
- # when the Comment is created. reset it here.
+ # we defer this assignment until we know that we have a saved patch
if patch:
comment.patch = patch
comment.submitter = author