fix: handle missing name/version fields in bento.yaml gracefully#5584
Open
Krishnachaitanyakc wants to merge 1 commit intobentoml:mainfrom
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
KeyError: 'name'crash whenbentoml buildencounters a bento.yaml created by an older version of BentoML that lacksnameandversionfields (e.g., pre-1.2 bentos stored alongside newer ones).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.BentoMLExceptionis raised instead of a rawKeyError, guiding the user to re-build or remove the outdated bento.versionwithout fallback.Fixes #4884
Test plan
test_from_yaml_file_missing_name_and_version_raises-- verifiesBentoMLExceptionis raised when bothnameandversionare missing and no fallback tag is provided.test_from_yaml_file_missing_name_and_version_with_fallback_tag-- verifies the fallback tag is used whenname/versionare absent.test_from_yaml_file_missing_only_version_raises-- verifiesBentoMLExceptionis raised when onlyversionis missing.test_bento_infotest still passes (no regression).