Skip to content

fix: handle missing name/version fields in bento.yaml gracefully#5584

Open
Krishnachaitanyakc wants to merge 1 commit intobentoml:mainfrom
Krishnachaitanyakc:fix/handle-missing-name-version-in-bento-yaml
Open

fix: handle missing name/version fields in bento.yaml gracefully#5584
Krishnachaitanyakc wants to merge 1 commit intobentoml:mainfrom
Krishnachaitanyakc:fix/handle-missing-name-version-in-bento-yaml

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown

Summary

  • Fixes KeyError: 'name' crash when bentoml build encounters a bento.yaml created by an older version of BentoML that lacks name and version fields (e.g., pre-1.2 bentos stored alongside newer ones).
  • When loaded via Bento.from_path() (i.e., from the bento store), the tag is now inferred from the directory structure (<store_base>/<name>/<version>/) as a fallback, enabling backward compatibility with old bentos.
  • When no fallback tag is available, a descriptive BentoMLException is raised instead of a raw KeyError, guiding the user to re-build or remove the outdated bento.
  • Adds three unit tests covering: missing both fields without fallback, missing both fields with fallback tag, and missing only version without fallback.

Fixes #4884

Test plan

  • Added test_from_yaml_file_missing_name_and_version_raises -- verifies BentoMLException is raised when both name and version are missing and no fallback tag is provided.
  • Added test_from_yaml_file_missing_name_and_version_with_fallback_tag -- verifies the fallback tag is used when name/version are absent.
  • Added test_from_yaml_file_missing_only_version_raises -- verifies BentoMLException is raised when only version is missing.
  • Verified existing test_bento_info test still passes (no regression).

When loading a bento.yaml created by an older version of BentoML that
lacks the 'name' and 'version' fields, a raw KeyError was raised,
crashing the build process. This fix catches the KeyError and either
falls back to inferring the tag from the directory structure (when
loaded via from_path) or raises a descriptive BentoMLException guiding
the user to re-build or remove the outdated bento.

Fixes bentoml#4884
@Krishnachaitanyakc Krishnachaitanyakc requested a review from a team as a code owner March 25, 2026 02:25
@Krishnachaitanyakc Krishnachaitanyakc requested review from parano and removed request for a team March 25, 2026 02:25
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.

bug: Getting KeyError when Name or version is missing from YAML Config

1 participant