Skip to content

Commit adaa399

Browse files
committed
Add regression test and changelog for namedtuple detailed_validation fix
Add a test that verifies the detailed_validation parameter passed to namedtuple_dict_structure_factory is actually used and not silently ignored. Also add a HISTORY.md entry for the fix.
1 parent 787e7d3 commit adaa399

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ The third number is for emergencies when we need to start branches for older rel
1111

1212
Our backwards-compatibility policy can be found [here](https://github.com/python-attrs/cattrs/blob/main/.github/SECURITY.md).
1313

14+
## NEXT
15+
16+
- Fix the `detailed_validation` parameter being passed under the wrong name in {func}`namedtuple_dict_structure_factory <cattrs.cols.namedtuple_dict_structure_factory>`, causing it to be silently ignored.
17+
([#723](https://github.com/python-attrs/cattrs/pull/723))
18+
1419
## 26.1.0 (2026-02-18)
1520

1621
- Add the {mod}`tomllib <cattrs.preconf.tomllib>` preconf converter.

tests/test_tuples.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,31 @@ class Test(NamedTuple):
141141

142142
assert isinstance(exc, ForbiddenExtraKeysError)
143143
assert exc.extra_fields == {"b"}
144+
145+
146+
def test_dict_namedtuples_detailed_validation():
147+
"""Passing detailed_validation to namedtuple_dict_structure_factory works.
148+
149+
Regression test for the parameter being passed under the wrong name.
150+
"""
151+
152+
class Test(NamedTuple):
153+
a: int
154+
155+
# Create a converter that does NOT use detailed validation by default.
156+
c = Converter(detailed_validation=False)
157+
158+
# But explicitly enable it in the factory.
159+
c.register_structure_hook_factory(
160+
lambda t: t is Test,
161+
lambda t, conv: namedtuple_dict_structure_factory(
162+
t, conv, detailed_validation=True
163+
),
164+
)
165+
166+
# With detailed validation, structuring errors should be wrapped
167+
# in a ClassValidationError instead of being raised directly.
168+
from cattrs.errors import ClassValidationError
169+
170+
with raises(ClassValidationError):
171+
c.structure({"a": "not_an_int"}, Test)

0 commit comments

Comments
 (0)