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

Conversation

aminiun
Copy link
Contributor

@aminiun aminiun commented Jun 24, 2023

My real scenario is when I include some fields that does not exists in the model. For example assume that I have a model called Store, which does not have token field.

In this example, if I have a ModelSerializer like this:

class StoreSerializer(ModelSerializer):
    ...
    class Meta:
        fields = (
            ...
            "token"
        )

Then I will face an exception like: 'Field name `token` is not valid for model `Store`.' .

This can really be a headache, when I have multiple serializers for Store model. So I suggest to simply have the model path, to be more clear about which serializer is corrupt.

@auvipy auvipy self-requested a review June 24, 2023 06:32
@aminiun
Copy link
Contributor Author

aminiun commented Jun 24, 2023

@auvipy I couldn't figure out why CI / Python 3.9 job failed. Isn't it a problem with CI ? Or my PR made this happen

@auvipy
Copy link
Member

auvipy commented Jun 24, 2023

that is unrelated with your PR

@aminiun
Copy link
Contributor Author

aminiun commented Jul 8, 2023

@auvipy Any plan for this PR ?

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be a good usability improvement

@auvipy auvipy added this to the 3.15 milestone Jul 25, 2023
@auvipy auvipy merged commit 5c3b6e4 into encode:master Jul 25, 2023
6 of 7 checks passed
math-a3k pushed a commit to math-a3k/django-rest-framework that referenced this pull request Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants