Skip to content

fix(betterlist): skip non-numeric indices to prevent ValueError on language page save#276

Open
ManthanNimodiya wants to merge 1 commit intointernetarchive:masterfrom
ManthanNimodiya:fix/betterlist-non-numeric-index
Open

fix(betterlist): skip non-numeric indices to prevent ValueError on language page save#276
ManthanNimodiya wants to merge 1 commit intointernetarchive:masterfrom
ManthanNimodiya:fix/betterlist-non-numeric-index

Conversation

@ManthanNimodiya
Copy link
Copy Markdown

Fixes internetarchive/openlibrary#11981

What changed

betterlist.setdefault() in infogami/core/helpers.py called int(index)
unconditionally. When the repetition widget in default_edit.html submits
unprocessed template placeholder rows (e.g. translated_names#[row_translated_names]),
unflatten() passes the placeholder string as the index, causing:

ValueError: invalid literal for int() with base 10: '[row_translated_names]'

This crash made language page editing completely broken via the UI for superusers.

Fix

Wrapped int(index) in a try/except (ValueError, TypeError) block.
Non-numeric indices are silently skipped (return None) — they are always invalid
in a list context and represent unrendered template rows that should be ignored.
All valid numeric indices continue to work exactly as before.

Tests

Added 3 doctests to betterlist.setdefault() covering:

  • normal numeric index (existing behaviour)
  • placeholder string '[row_translated_names]' → returns None
  • list remains unchanged after skipped index

All 15 existing doctests in infogami/core/helpers.py pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editing and saving a language page errors and does not save

1 participant