Skip to content

Commit

Permalink
fix: resolve unreachable exception when schema is not a class
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwaller committed Jan 11, 2025
1 parent be4831b commit ca8e63b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,13 @@ class TestEnum(Enum):
(2, 2),
],
} == convert(vol.Schema(vol.Coerce(TestEnum)))


def test_invalid_schema():
# check if an exception is raised when an invalid schema is passed
try:
convert(vol.Schema(None))
except Exception as e:
assert str(e) == "Unable to convert schema: None"
else:
assert False, "Expected an exception to be raised"
2 changes: 1 addition & 1 deletion voluptuous_serialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def convert(schema, *, custom_serializer=None):
if isinstance(schema, (str, int, float, bool)):
return {"type": "constant", "value": schema}

if issubclass(schema, Enum):
if isinstance(schema, type) and issubclass(schema, Enum):
return {
"type": "select",
"options": [(item.value, item.value) for item in schema],
Expand Down

0 comments on commit ca8e63b

Please sign in to comment.