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

Invalid filter for properties of model of RelatedMultipleFilter #349

Open
petrosschilling opened this issue Oct 22, 2020 · 1 comment
Open

Comments

@petrosschilling
Copy link

Version: 1.0.0.dev2
Python version: 3.6.11

Other dependencies:
Django==3.0
django-cors-headers==3.5.0
django-filter==2.4.0
django-hashid-field==3.1.3
djangorestframework==3.11.1
djangorestframework-filters==1.0.0.dev2
djangorestframework-jsonapi==3.2.0
djangorestframework-simplejwt==4.4.0
dry-rest-permissions==0.1.10

I know I'm using a dev version but i'm putting the issue here for the record.

I have the following structure:

class IndividualFilterSet(FilterSet):
    class Meta:
        model = Individual
        fields = {
            "first_name": ["exact", "icontains"],
            "last_name": ["exact", "icontains"],
            "mobile_phone": ["exact", "icontains"],
        }

class ClientAccountFilterSet(FilterSet):
    individuals = RelatedMultipleFilter(IndividualFilterSet, queryset=Individual.objects.all())

    class Meta:
        model = ClientAccount
        fields = {
            "is_lead": ["exact"],
            "user_reference": ["exact", "icontains"],
        }

But when making a get request on /client_accounts/?filter[individuals.first_name]=Tes I get the following error:

{
    "errors": [
        {
            "detail": "invalid filter[individuals__first_name]",
            "status": "400",
            "source": {
                "pointer": "/data"
            },
            "code": "invalid"
        }
    ]
}

If I add the field to individuals__first_name to the client ClientAccountFilterSet Meta fields like the following. I passes through the validation.

class ClientAccountFilterSet(FilterSet):
    individuals = RelatedMultipleFilter(IndividualFilterSet, queryset=Individual.objects.all())

    class Meta:
        model = ClientAccount
        fields = {
            "is_lead": ["exact"],
            "user_reference": ["exact", "icontains"],
            "individuals__first_name": ["exact", "icontains"],
        }

As far as I understand when using related filter I should not have to specify all the properties within the related class in the filter because that is already specified in the IndividualFilterSet. Like the case of the Individual.first_name.

Any help on this is much appreciated.

@petrosschilling petrosschilling changed the title Invalid filter for properties of model of RelatedFilter Invalid filter for properties of model of RelatedMultipleFilter Oct 22, 2020
@petrosschilling
Copy link
Author

The issue seems to be in the FilterSetMetaclass.expand_auto_filter() function which always return an empty OrderedDict().

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

No branches or pull requests

1 participant