]> git.ozlabs.org Git - patchwork/commit
patchwork/parser: Adapt for new unsaved-foreign-key behaviour in django 1.8
authorJeremy Kerr <jk@ozlabs.org>
Fri, 5 Jun 2015 06:33:13 +0000 (14:33 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 5 Jun 2015 06:37:48 +0000 (14:37 +0800)
commit41d5ceb82b5d4297570b73639517b642fab0c45f
tree87af4cff500d1dcd39be8d3678ec8a81f0fefd35
parent30bb271ca25b9652744c3c17d9bc35cde91c6dc3
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>
patchwork/bin/parsemail.py