diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 56fa918dc..6ee75fbc1 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -1372,8 +1372,8 @@ class ModelSerializer(Serializer): Raise an error on any unknown fields. """ raise ImproperlyConfigured( - 'Field name `%s` is not valid for model `%s`.' % - (field_name, model_class.__name__) + 'Field name `%s` is not valid for model `%s` in `%s.%s`.' % + (field_name, model_class.__name__, self.__class__.__module__, self.__class__.__name__) ) def include_extra_kwargs(self, kwargs, extra_kwargs): diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index c5ac888f5..e2d4bbc30 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -315,7 +315,8 @@ class TestRegularFieldMappings(TestCase): model = RegularFieldsModel fields = ('auto_field', 'invalid') - expected = 'Field name `invalid` is not valid for model `RegularFieldsModel`.' + expected = 'Field name `invalid` is not valid for model `RegularFieldsModel` ' \ + 'in `tests.test_model_serializer.TestSerializer`.' with self.assertRaisesMessage(ImproperlyConfigured, expected): TestSerializer().fields