Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ The third number is for emergencies when we need to start branches for older rel

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

## NEXT

- 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.
([#723](https://github.com/python-attrs/cattrs/pull/723))

## 26.1.0 (2026-02-18)

- Add the {mod}`tomllib <cattrs.preconf.tomllib>` preconf converter.
Expand Down
2 changes: 1 addition & 1 deletion src/cattrs/cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def namedtuple_dict_structure_factory(
cl,
converter,
_cattrs_forbid_extra_keys=forbid_extra_keys,
_cattrs_use_detailed_validation=detailed_validation,
_cattrs_detailed_validation=detailed_validation,
_cattrs_use_linecache=use_linecache,
**kwargs,
)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,31 @@ class Test(NamedTuple):

assert isinstance(exc, ForbiddenExtraKeysError)
assert exc.extra_fields == {"b"}


def test_dict_namedtuples_detailed_validation():
"""Passing detailed_validation to namedtuple_dict_structure_factory works.

Regression test for the parameter being passed under the wrong name.
"""

class Test(NamedTuple):
a: int

# Create a converter that does NOT use detailed validation by default.
c = Converter(detailed_validation=False)

# But explicitly enable it in the factory.
c.register_structure_hook_factory(
lambda t: t is Test,
lambda t, conv: namedtuple_dict_structure_factory(
t, conv, detailed_validation=True
),
)

# With detailed validation, structuring errors should be wrapped
# in a ClassValidationError instead of being raised directly.
from cattrs.errors import ClassValidationError

with raises(ClassValidationError):
c.structure({"a": "not_an_int"}, Test)
Loading