Merge pull request #461 from AdamDonna/fix/455/failures_on_django_master

Fixes issue 455 (incompatability with django master at 3.2)
fix_request_path_info^2
Chris Glass 2020-08-21 11:34:28 +02:00 committed by GitHub
commit c005410da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 13 deletions

View File

@ -13,6 +13,7 @@ Contributors
* Abel Daniel * Abel Daniel
* Adam Chainz * Adam Chainz
* Adam Wentz * Adam Wentz
* Adam Donaghy
* Andrew Ingram (contributed setup.py) * Andrew Ingram (contributed setup.py)
* Al Johri * Al Johri
* Alex Alvarez * Alex Alvarez

View File

@ -5,6 +5,7 @@ QuerySet for PolymorphicModel
import copy import copy
from collections import defaultdict from collections import defaultdict
from django import get_version as get_django_version
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldDoesNotExist from django.core.exceptions import FieldDoesNotExist
from django.db.models.query import ModelIterable, Q, QuerySet from django.db.models.query import ModelIterable, Q, QuerySet
@ -157,8 +158,24 @@ class PolymorphicQuerySet(QuerySet):
# Implementation in _translate_polymorphic_filter_defnition.""" # Implementation in _translate_polymorphic_filter_defnition."""
return self.filter(not_instance_of=args) return self.filter(not_instance_of=args)
# Makes _filter_or_exclude compatible with the change in signature introduced in django at 9c9a3fe
if get_django_version() >= "3.2":
def _filter_or_exclude(self, negate, args, kwargs):
# We override this internal Django function as it is used for all filter member functions.
q_objects = translate_polymorphic_filter_definitions_in_args(
queryset_model=self.model, args=args, using=self.db
)
# filter_field='data'
additional_args = translate_polymorphic_filter_definitions_in_kwargs(
queryset_model=self.model, kwargs=kwargs, using=self.db
)
args = list(q_objects) + additional_args
return super(PolymorphicQuerySet, self)._filter_or_exclude(
negate=negate, args=args, kwargs=kwargs
)
else:
def _filter_or_exclude(self, negate, *args, **kwargs): def _filter_or_exclude(self, negate, *args, **kwargs):
# We override this internal Django functon as it is used for all filter member functions. # We override this internal Django function as it is used for all filter member functions.
q_objects = translate_polymorphic_filter_definitions_in_args( q_objects = translate_polymorphic_filter_definitions_in_args(
self.model, args, using=self.db self.model, args, using=self.db
) )