DOn't crash on very long annotations
authorMagnus Hagander <magnus@hagander.net>
Tue, 10 Dec 2024 12:09:10 +0000 (13:09 +0100)
committerMagnus Hagander <magnus@hagander.net>
Tue, 10 Dec 2024 12:09:10 +0000 (13:09 +0100)
When a very long annotation is posted, we would crash if it's shorter
than 500 characters, but the length of the *log* message became longer
than 500. To handle this, shorten the text in the log message if it's
too long.

pgcommitfest/commitfest/ajax.py

index e2fcb55e1666095b558c9a7dfb83e5abad2ad0c9..eaf7cdc85dd886afb492012a32dc6326db72d669 100644 (file)
@@ -8,6 +8,7 @@ from django.db import transaction
 
 import requests
 import json
+import textwrap
 
 from pgcommitfest.auth import user_search
 from .models import CommitFest, Patch, MailThread, MailThreadAttachment
@@ -114,7 +115,7 @@ def annotateMessage(request):
             annotation.save()
 
             for p in thread.patches.all():
-                PatchHistory(patch=p, by=request.user, what='Added annotation "%s" to %s' % (msg, msgid)).save_and_notify()
+                PatchHistory(patch=p, by=request.user, what='Added annotation "%s" to %s' % (textwrap.shorten(msg, 100), msgid)).save_and_notify()
                 p.set_modified()
                 p.save()