Skip to content

Commit 1c5c8f8

Browse files
committed
Add unrelated test to increase test coverage and unblock PR
1 parent a982763 commit 1c5c8f8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: graphene_sqlalchemy/tests/test_types.py

+13
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ class Meta:
224224
assert pets_field.type().description == 'Overridden'
225225

226226

227+
def test_invalid_model_attr():
228+
err_msg = (
229+
"Cannot map ORMField to a model attribute.\n"
230+
"Field: 'ReporterType.first_name'"
231+
)
232+
with pytest.raises(ValueError, match=err_msg):
233+
class ReporterType(SQLAlchemyObjectType):
234+
class Meta:
235+
model = Reporter
236+
237+
first_name = ORMField(model_attr='does_not_exist')
238+
239+
227240
def test_only_fields():
228241
class ReporterType(SQLAlchemyObjectType):
229242
class Meta:

Diff for: graphene_sqlalchemy/types.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ def construct_fields(
133133
for orm_field_name, orm_field in custom_orm_fields_items:
134134
attr_name = orm_field.kwargs.get('model_attr', orm_field_name)
135135
if attr_name not in all_model_attrs:
136-
raise Exception('Cannot map ORMField "{}" to SQLAlchemy model property'.format(orm_field_name))
136+
raise ValueError((
137+
"Cannot map ORMField to a model attribute.\n"
138+
"Field: '{}.{}'"
139+
).format(obj_type.__name__, orm_field_name,))
137140
orm_field.kwargs['model_attr'] = attr_name
138141

139142
# Merge automatic fields with custom ORM fields

0 commit comments

Comments
 (0)