File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,19 @@ class Meta:
224
224
assert pets_field .type ().description == 'Overridden'
225
225
226
226
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
+
227
240
def test_only_fields ():
228
241
class ReporterType (SQLAlchemyObjectType ):
229
242
class Meta :
Original file line number Diff line number Diff line change @@ -133,7 +133,10 @@ def construct_fields(
133
133
for orm_field_name , orm_field in custom_orm_fields_items :
134
134
attr_name = orm_field .kwargs .get ('model_attr' , orm_field_name )
135
135
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 ,))
137
140
orm_field .kwargs ['model_attr' ] = attr_name
138
141
139
142
# Merge automatic fields with custom ORM fields
You can’t perform that action at this time.
0 commit comments