[Patchew-devel] [PATCH] api: handle "[PATCH 3/4/5]" in the subject line

Paolo Bonzini posted 1 patch 1 week, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20220919073743.8625-1-pbonzini@redhat.com
api/models.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[Patchew-devel] [PATCH] api: handle "[PATCH 3/4/5]" in the subject line
Posted by Paolo Bonzini 1 week, 1 day ago
Avoids errors like

Traceback (most recent call last):
  ...
  File "/opt/patchew/www/views.py", line 53, in prepare_message
    m.num_patches = m.get_num_patches()
  File "/opt/patchew/api/models.py", line 806, in get_num_patches
    self.refresh_num_patches()
  File "/opt/patchew/api/models.py", line 787, in refresh_num_patches
    c, n = self.get_num()
  File "/opt/patchew/api/models.py", line 737, in get_num
    n, m = tag.split("/")
ValueError: too many values to unpack (expected 2)

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/models.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/api/models.py b/api/models.py
index c4f10da..cd0285d 100644
--- a/api/models.py
+++ b/api/models.py
@@ -734,7 +734,9 @@ class Message(models.Model):
         cur, total = 1, 1
         for tag in self.prefixes:
             if "/" in tag:
-                n, m = tag.split("/")
+                # Adding the slash at the end ensures that both "3/4" and "3/4/5"
+                # are parsed correctly.
+                n, m, _ = (tag + "/").split("/", maxsplit=2)
                 try:
                     cur, total = int(n), int(m)
                     break
-- 
2.37.2

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/patchew-devel