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

union + instance_of doesn't work in Django 3 #467

Closed
l0b0 opened this issue Sep 23, 2020 · 1 comment
Closed

union + instance_of doesn't work in Django 3 #467

l0b0 opened this issue Sep 23, 2020 · 1 comment

Comments

@l0b0
Copy link

l0b0 commented Sep 23, 2020

I've been using several polymorphic model filters to get only the instances of specific types. For example:

class MyModelFilter(FilterSet):
    def polymorphic_type_filter(self, queryset: PolymorphicQuerySet, name: str, type_names: Iterable[str]) -> QuerySet:
        type_models = []
        for model_class in MyModelPolymorphicSerializer.model_serializer_mapping.keys():
            if model_class.__name__ in type_names:
                type_models.append(model_class)

        return queryset.instance_of(*type_models)

    resourcetype__in = CharInFilter(method=polymorphic_type_filter.__name__, field_name="resourcetype")

Django 3 no longer allows filtering a union query set, so after upgrading this filter results in the following error:

django.db.utils.NotSupportedError: Calling QuerySet.filter() after union() is not supported.

I'm looking for a workaround for this, but I'm not sure how easy this is to do. Is there a known fix?

The weird thing is, this ticket says this never used to work, but I've got tests which say otherwise.

@l0b0
Copy link
Author

l0b0 commented Sep 23, 2020

Looks like this might've been a red herring. Sorry for the noise.

@l0b0 l0b0 closed this as completed Sep 23, 2020
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