diff options
author | Stephen Finucane <stephen@that.guru> | 2018-09-19 21:03:33 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2018-09-20 22:06:14 +0100 |
commit | 300ba3eb283ab1af3dc5924e5ed540159c3ee0bc (patch) | |
tree | 60bc0b8621e260a397a7e1902ba3f091237c6dcf /patchwork/parser.py | |
parent | 133091da0a527ef8fe89aea38c4855973b48d5f1 (diff) | |
download | patchwork-300ba3eb283ab1af3dc5924e5ed540159c3ee0bc.tar patchwork-300ba3eb283ab1af3dc5924e5ed540159c3ee0bc.tar.gz |
parser: Handle IntegrityError for cover letters, comments
This was already done for patches but cover letters and comments were
not handled correctly, resulting in errors while parsing archives. While
we're here, we slightly modify how these exceptions are handle. Rather
than simply ignoring them, as we were doing, we raise a custom
exception. This allows us to specifically identify these types of
exceptions, print a log and still skip them (which we want, as seen in
commit d2eb1f6d2).
While we're here, we change from separate create-save calls to a
combined create-save call for both created CoverLetter and Comment
objects. We were already doing this for patches.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'patchwork/parser.py')
-rw-r--r-- | patchwork/parser.py | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/patchwork/parser.py b/patchwork/parser.py index a61669f..eb78702 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -41,6 +41,12 @@ SERIES_DELAY_INTERVAL = 10 logger = logging.getLogger(__name__) +class DuplicateMailError(Exception): + + def __init__(self, msgid): + self.msgid = msgid + + def normalise_space(value): whitespace_re = re.compile(r'\s+') return whitespace_re.sub(' ', value).strip() @@ -1014,8 +1020,7 @@ def parse_mail(mail, list_id=None): state=find_state(mail)) logger.debug('Patch saved') except IntegrityError: - logger.error("Duplicate mail for message ID %s" % msgid) - return None + raise DuplicateMailError(msgid=msgid) # if we don't have a series marker, we will never have an existing # series to match against. @@ -1121,15 +1126,18 @@ def parse_mail(mail, list_id=None): logger.error("Multiple SeriesReferences for %s" " in project %s!" % (msgid, project.name)) - cover_letter = CoverLetter( - msgid=msgid, - project=project, - name=name[:255], - date=date, - headers=headers, - submitter=author, - content=message) - cover_letter.save() + try: + cover_letter = CoverLetter.objects.create( + msgid=msgid, + project=project, + name=name[:255], + date=date, + headers=headers, + submitter=author, + content=message) + except IntegrityError: + raise DuplicateMailError(msgid=msgid) + logger.debug('Cover letter saved') series.add_cover_letter(cover_letter) @@ -1145,14 +1153,18 @@ def parse_mail(mail, list_id=None): author = get_or_create_author(mail) - comment = Comment( - submission=submission, - msgid=msgid, - date=date, - headers=headers, - submitter=author, - content=message) - comment.save() + + try: + comment = Comment.objects.create( + submission=submission, + msgid=msgid, + date=date, + headers=headers, + submitter=author, + content=message) + except IntegrityError: + raise DuplicateMailError(msgid=msgid) + logger.debug('Comment saved') return comment |