Name the offending key when per_key_traits rejects a value - #978
Open
sap1110 wants to merge 1 commit into
Open
Conversation
A Dict configured with per_key_traits reported failures against the trait as a
whole, so the message named the trait but not the key that was actually invalid:
Values of the 'bar' trait of a Foo instance must be a dict, but a value of
False <class 'bool'> was specified.
With several per-key traits configured, that leaves the caller to work out which
key the message is about. Failures routed through a per_key_traits entry now
name it:
Value at key 'that' of the 'bar' trait of a Foo instance must be a dict, but
a value of False <class 'bool'> was specified.
Only the per-key path changes. A uniform value_trait failure still reports
against the trait as a whole, and there is a test covering that.
Codecov Report✅ All modified and coverable lines are covered by tests.
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Closes #920
A
Dictconfigured withper_key_traitsreports failures against the trait as a whole, so the message names the trait but never the key that was actually invalid:With more than one per-key trait configured, that leaves the caller to work out which key the message is about. Failures routed through a
per_key_traitsentry now name it:Only the per-key path changes: it goes through a new
per_key_element_errorrather thanelement_error, so a uniformvalue_traitfailure still reports against the trait as a whole. There's a test asserting that, since the wording of these messages is the sort of thing downstream test suites match on.Not addressed here
The issue also mentions nested dicts. Those are still misreported, and the cause is separate from the key naming:
The value is a dict. The inner trait raises an accurate error, and the outer
validate_elementsdiscards it and substitutes its own.TraitType.erroralready has a chaining protocol for exactly this (child errors carrying(value, info, *traits)), whichDict.validate_elementsbypasses.Routing per-key failures through that protocol would fix the nested case, but it changes a shared error contract and the composed message shape, so it seemed worth agreeing on separately rather than folding into this one. Happy to do it in a follow-up if you'd like it, in whichever direction you prefer.
🤖🍆 Prepared with the help of an AI coding agent, marked as the contributing guide asks agents to do. Reviewed and tested by me.