Skip to content

Commit

Permalink
use TypeError over asserts and fix filter exception tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sabard committed Mar 4, 2024
1 parent 7d87235 commit bd2b3d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions graphene_sqlalchemy/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ def __init_subclass_with_meta__(
new_filter_fields = {}
# Generate Graphene Fields from the filter functions based on type hints
for field_name, _annotations in logic_functions:
assert (
"val" in _annotations
), "Each filter method must have a value field with valid type annotations"
if "val" not in _annotations:
raise TypeError(

Check warning on line 83 in graphene_sqlalchemy/filters.py

View check run for this annotation

Codecov / codecov/patch

graphene_sqlalchemy/filters.py#L83

Added line #L83 was not covered by tests
"Each filter method must have a 'val' field with valid type annotations."
)

# If type is generic, replace with actual type of filter class

replace_type_vars = {BaseTypeFilterSelf: cls}
Expand Down Expand Up @@ -252,9 +254,11 @@ def __init_subclass_with_meta__(cls, graphene_type=None, _meta=None, **options):
new_filter_fields = {}
# Generate Graphene Fields from the filter functions based on type hints
for field_name, _annotations in filter_functions:
assert (
"val" in _annotations
), "Each filter method must have a value field with valid type annotations"
if "val" not in _annotations:
raise TypeError(
"Each filter method must have a 'val' field with valid type annotations."
)

# If type is generic, replace with actual type of filter class
replace_type_vars = {ScalarFilterInputType: _meta.graphene_type}
field_type = convert_sqlalchemy_type(
Expand Down
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ async def test_filter_relationship_no_base_type(session):


@pytest.mark.asyncio
async def test_filter_(session):
async def test_filter_invalid_filter_method(session):
with pytest.raises(
TypeError,
match=r"(.*)Each filter method must have a 'val' field with valid type annotations.(.*)",
Expand Down

0 comments on commit bd2b3d0

Please sign in to comment.