From cdc1c6a3b6a1920c66c29b0e28e9ba13c31d2fef Mon Sep 17 00:00:00 2001 From: ManthanNimodiya Date: Fri, 6 Mar 2026 16:41:57 +0530 Subject: [PATCH] fix(betterlist): skip non-numeric indices to prevent ValueError Fixes internetarchive/openlibrary#11981 --- infogami/core/helpers.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/infogami/core/helpers.py b/infogami/core/helpers.py index 791e2a68..6c6687b6 100644 --- a/infogami/core/helpers.py +++ b/infogami/core/helpers.py @@ -86,7 +86,24 @@ def fill(self, size): self.append(None) def setdefault(self, index, value): - index = int(index) + """Set a value at the given index, expanding the list as needed. + + Non-numeric indices (e.g. template placeholders like + '[row_translated_names]') are silently ignored so that unprocessed + repetition-widget rows do not crash form submission. + + >>> bl = betterlist() + >>> bl.setdefault('0', 'a') + 'a' + >>> bl.setdefault('[row_translated_names]', 'x') is None + True + >>> bl # list is unchanged after non-numeric index + ['a'] + """ + try: + index = int(index) + except (ValueError, TypeError): + return None self.fill(index + 1) if self[index] is None: self[index] = value