Python(fix): tolerate multi-value metadata keys in metadata_proto_to_dict - #698
Draft
dengjonathan wants to merge 1 commit into
Draft
Python(fix): tolerate multi-value metadata keys in metadata_proto_to_dict#698dengjonathan wants to merge 1 commit into
dengjonathan wants to merge 1 commit into
Conversation
…dict A metadata key can hold multiple values once the multi-value-metadata feature ships. metadata_proto_to_dict raised ValueError on the second value of a key, which made Run/Asset._from_proto -- and therefore client.runs.get()/list_() -- crash for any entity carrying multi-value metadata. Keep the first value per key instead (the API returns values in canonical order), matching the value backend single-value contexts use. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Python docs preview: https://sift-stack.github.io/sift/python/pr-698/ Deployed from |
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.
What
metadata_proto_to_dictraisesValueError("Key already exists")when the repeatedMetadataValuelist contains the same key twice. Once the backend's org-scopedmulti-value-metadatafeature ships (azimuth ENG-9885), a metadata key can legitimately hold multiple values — and becauseRun._from_proto/Asset._from_protocall this helper,client.runs.get()/list_()crash outright for any entity carrying multi-value metadata. This also breaks azimuth's isolated rule runner and canvas parameter hydration, which fetch entities through this client.This PR makes the helper keep the first value per key instead of raising. The API returns values in canonical order (the backend assigns
order_indexdeterministically on write), so "first" is stable and matches the value every backend single-value context uses (e.g. azimuth'sMetadataToFlatMap).Why first-value rather than lists
Returning lists would change the type of
.metadatavalues and break every existing caller. First-value keeps the dict view exactly as it is today for single-valued keys and degrades gracefully for multi-valued ones. Full list access (a dict-compatibleMetadatamapping withgetall(key), plus list writes) is scoped separately in Linear ENG-13281 — this PR is deliberately the minimal forward-compatibility fix.Rollout note
This must be released before the
multi-value-metadataflag is enabled for any org: every published sift-py version crashes on fetch the moment an org writes its first multi-value key. Tracked with an org-enablement checklist in ENG-13281.Testing
New
_tests/util/test_metadata.py(first test module for this util): value-type unwrapping, multi-value first-value behavior, empty input, and a dict→proto→dict round trip.ruff checkandruff format --checkpass on the changed files.Linear: ENG-13281 (client multi-value support), ENG-13104 (rule payload counterpart), ENG-9885 (feature)
🤖 Generated with Claude Code