Skip to content
Merged
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
2 changes: 1 addition & 1 deletion schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def validate(self, data: Any, **kwargs: Dict[str, Any]) -> Any:
svalue, error=e, ignore_extra_keys=i
).validate(value, **kwargs)
except SchemaError as x:
k = "Key '%s' error:" % nkey
k = "Key '%s' error:" % (nkey,)
message = self._prepend_schema_name(k)
raise SchemaError(
[message] + x.autos,
Expand Down
10 changes: 10 additions & 0 deletions test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2059,3 +2059,13 @@ def test_callable_error():
except SchemaError as ex:
e = ex
assert e.errors == ["This is the error message"]


def test_tuple_key_error_message_does_not_crash():
# Regression test for #253: a tuple dict key (including the empty tuple) must not raise
# "TypeError: not enough arguments for format string" when building the key error message.
assert Schema({(): [(str,)]}).is_valid({(): ["foo", ("bar",)]}) is False

with raises(SchemaError) as exc_info:
Schema({("a", "b"): int}).validate({("a", "b"): "not-an-int"})
assert "Key '('a', 'b')' error:" in exc_info.value.code
Loading