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
6 changes: 5 additions & 1 deletion schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,11 @@ def validate(self, data: Any, **kwargs: Dict[str, Any]) -> Any:
for skey in sorted_skeys:
svalue = s[skey]
try:
nkey = Schema(skey, error=e).validate(key, **kwargs)
if isinstance(skey, (tuple, frozenset)):
Schema(hash(skey), error=e).validate(hash(key), **kwargs)
nkey = skey
else:
nkey = Schema(skey, error=e).validate(key, **kwargs)
except SchemaError:
pass
else:
Expand Down
22 changes: 22 additions & 0 deletions test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1985,3 +1985,25 @@ def test_callable_error():
except SchemaError as ex:
e = ex
assert e.errors == ["This is the error message"]


def test_tuple_key_of_dict():
# this is a simplified regression test of the bug in github issue #312
assert Schema({('map_point', 'to', 'map_polygon'): {}}).validate(
{('map_point', 'to', 'map_polygon'): {}}
) == {('map_point', 'to', 'map_polygon'): {}}
with SE:
assert Schema({('map_point', 'to', 'map_polygon'): {}}).validate(
{('map_polygon', 'to', 'map_polygon'): {}}
) == {('map_polygon', 'to', 'map_polygon'): {}}


def test_frozenset_key_of_dict():
# this is a simplified regression test of the bug in github issue #312
assert Schema({frozenset(('map_point', 'to', 'map_polygon')): {}}).validate(
{frozenset(('map_point', 'to', 'map_polygon')): {}}
) == {frozenset(('map_point', 'to', 'map_polygon')): {}}
with SE:
assert Schema({frozenset(('map_point', 'to', 'map_polygon')): {}}).validate(
{frozenset(('map_polygon', 'to', 'map_polygon')): {}}
) == {frozenset(('map_polygon', 'to', 'map_polygon')): {}}