Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unknown field error in ModelSerializer #9019

Merged
merged 2 commits into from Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions rest_framework/serializers.py
Expand Up @@ -1372,8 +1372,8 @@ def build_unknown_field(self, field_name, model_class):
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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_model_serializer.py
Expand Up @@ -315,7 +315,8 @@ class Meta:
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

Expand Down