python-attrs / python-attrs/attrs
Wrong error message for inner validators
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
This is a copy of the third issue collected in https://github.com/python-attrs/attrs/issues/1206 to enable separate tracking of the bug.
The issue
When a validation error in one of the inner validators of deep_iterable or deep_mapping occurs, an exception is thrown but the contained message is wrong. For example, using the following code:
@define
class A:
x: List[str] = field(
validator=deep_iterable(
member_validator=[instance_of(str), min_len(1)],
iterable_validator=and_(instance_of(list), min_len(1)),
),
)
and calling A(["abc", ""]), you get the following error:
ValueError: Length of 'x' must be => 1: 0
It rightfully complains about the length of the second item in the list, but note that the message refers to attribute name x, which is incorrect, since it's not x that is too short but one of its items.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Python reproduction in the issue with deep_iterable and deep_mapping, especially A(["abc", ""]). Trace how the inner validator constructs its ValueError message and verify that the reported name identifies the failing item rather than the outer attribute x; add coverage for this example if the project’s existing validator tests provide a suitable location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100