Skip to content

Return proper error message when wrong category query parameter is provided. #2701

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

teymour-aldridge
Copy link
Contributor

No description provided.

@tienne-B
Copy link
Member

tienne-B commented Jul 21, 2025

Sorry I haven't replied on GitHub about this yet. I just don't think we should be implementing such type checks, as that's the purpose of having serializers, which would be able to have more precise checks (such as that the category exists) and being more generalizable for all the possible query parameters that are passed.

I would recommend approaching this by creating new serializers that can take the query parameters, validate them, and then use them in the query. This may look like:

class TeamStandingsView:
    class QueryParameters(Serializer):
        category = PrimaryKeyRelatedField()

    ...
    def get_queryset(self):
        self.QueryParameters(data=self.request.query_params).is_valid(raise_exception=True)

There would be more boilerplate, but now it's easier to add more params and have them tested (often with automatic error messages)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants