Skip to content

fix(device): Device.from_str crashes on a multi-colon device string#11519

Closed
devteamaegis wants to merge 1 commit into
deepset-ai:mainfrom
devteamaegis:fix/device-from-str-multicolon
Closed

fix(device): Device.from_str crashes on a multi-colon device string#11519
devteamaegis wants to merge 1 commit into
deepset-ai:mainfrom
devteamaegis:fix/device-from-str-multicolon

Conversation

@devteamaegis
Copy link
Copy Markdown

What's broken

_split_device_string unpacks string.split(":") into exactly two variables with no maxsplit. A device string with a second colon raises an uncaught error through the public Device.from_str:

>>> from haystack.utils.device import Device
>>> Device.from_str("cuda:0:1")
ValueError: too many values to unpack (expected 2)

Why it happens

str.split(":") without maxsplit=1 returns more than two parts when the string has more than one colon.

Fix

Use split(":", maxsplit=1). "cuda:0:1" then splits to ("cuda", "0:1"); int("0:1") fails and raises the function's existing, descriptive ValueError("Device id must be an integer, got 0:1") instead of the opaque unpack error.

Test

Added a case asserting Device.from_str("cuda:0:1") raises ValueError about the device id; "cuda:0" and "cpu" still parse correctly.

Fixes #11518

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

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

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Jun 4, 2026
@CLAassistant
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 sign our Contributor License Agreement before we can accept your contribution.


Ishaan Samantray seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

Coverage report

Click to see where and how coverage changed

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

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

@sjrl
Copy link
Copy Markdown
Contributor

sjrl commented Jun 5, 2026

This same PR was already closed here #11452 with the reasoning provided here #11452 (comment)

@sjrl sjrl closed this Jun 5, 2026
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.

Device.from_str crashes with "too many values to unpack" on a multi-colon device string

3 participants