Skip to content

fix(utils): raise clear ValueError for multi-hyphen page range strings - #11450

Closed
devteamaegis wants to merge 9 commits into
deepset-ai:mainfrom
devteamaegis:fix/valueerror-too-many-values-to-unpack
Closed

fix(utils): raise clear ValueError for multi-hyphen page range strings#11450
devteamaegis wants to merge 9 commits into
deepset-ai:mainfrom
devteamaegis:fix/valueerror-too-many-values-to-unpack

Conversation

@devteamaegis

Copy link
Copy Markdown
Contributor

What's broken

expand_page_range() in haystack/utils/misc.py crashes with ValueError: too many values to unpack (expected 2) when any element of the input list contains more than one hyphen, e.g. "5-10-15". This is a confusing internal error — the function should detect malformed input and raise a descriptive ValueError instead. The function is a public utility used by the PDF-to-image converter and LLM metadata extractor components.

Why it happens

Line 58 calls page.split("-") without a maxsplit argument and immediately unpacks into exactly two variables. When the string has more than one hyphen, split() returns more than 2 elements, causing the internal unpack error rather than a clean validation failure.

Fix

Added maxsplit=1 to the split call and added a validation check that both resulting parts are digit strings. Malformed ranges now raise ValueError: Invalid page range: <value> - range must be a string in the format 'start-end', consistent with the error message used elsewhere in the function.

Test

Added TestExpandPageRange.test_malformed_range_with_multiple_hyphens_raises_clear_valueerror in test/utils/test_misc.py. It passes ["1-3", "5-10-15"] and asserts that a ValueError matching "Invalid page range" is raised.

Fixes #11449

devteamaegis added 2 commits May 31, 2026 18:59
expand_page_range() called page.split("-") without maxsplit, then
unpacked into exactly two variables. A range string like "5-10-15"
produced "too many values to unpack" instead of a useful error message.

Add maxsplit=1 and validate that both parts are digit strings before
expanding the range, raising a descriptive ValueError for malformed input.

Fixes deepset-ai#11449
@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown

@devteamaegis is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented May 31, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ davidsbatista
❌ devteamaegis
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels May 31, 2026
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/utils
  misc.py 57
Project Total  

This report was generated by python-coverage-comment-action

@davidsbatista

Copy link
Copy Markdown
Contributor

@devteamaegis thanks for this contribution, you need to sign the CLA in order for the PR to be merged.

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Jun 1, 2026 2:37pm

Request Review

@davidsbatista

Copy link
Copy Markdown
Contributor

opened new PR due to user's inactivity #11475

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

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: expand_page_range() raises confusing ValueError for multi-hyphen range strings

4 participants