diff --git a/eav/models.py b/eav/models.py index 25639d6..af4f1a8 100644 --- a/eav/models.py +++ b/eav/models.py @@ -11,7 +11,6 @@ Along with the :class:`Entity` helper class. ''' from copy import copy -from django.conf import settings from django.contrib.contenttypes import fields as generic from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError diff --git a/eav/queryset.py b/eav/queryset.py index 9014465..8ed05f6 100644 --- a/eav/queryset.py +++ b/eav/queryset.py @@ -94,7 +94,6 @@ def rewrite_q_expr(model_cls, expr): if isinstance(expr, Q): config_cls = getattr(model_cls, '_eav_config_cls', None) - assert config_cls gr_name = config_cls.generic_relation_attr # Recurively check child nodes. @@ -111,11 +110,13 @@ def rewrite_q_expr(model_cls, expr): other = [c for c in expr.children if not c in rewritable] for child in rewritable: - assert child.children and len(child.children) == 1 + if not (child.children and len(child.children) == 1): + raise AssertionError('Child must have exactly one descendant') # Child to be merged is always a terminal Q node, # i.e. it's an AND expression with attribute-value tuple child. attrval = child.children[0] - assert isinstance(attrval, tuple) + if not isinstance(attrval, tuple): + raise AssertionError('Attribute-value must be a tuple') fname = '{}__in'.format(gr_name) @@ -261,7 +262,7 @@ class EavQuerySet(QuerySet): Pass *args* and *kwargs* through ``eav_filter``, then pass to the ``models.Manager`` filter method. ''' - return super(self.__class__, self).filter(*args, **kwargs) + return super().filter(*args, **kwargs) @eav_filter def exclude(self, *args, **kwargs): @@ -269,7 +270,7 @@ class EavQuerySet(QuerySet): Pass *args* and *kwargs* through ``eav_filter``, then pass to the ``models.Manager`` exclude method. ''' - return super(self.__class__, self).exclude(*args, **kwargs) + return super().exclude(*args, **kwargs) @eav_filter def get(self, *args, **kwargs): @@ -277,4 +278,4 @@ class EavQuerySet(QuerySet): Pass *args* and *kwargs* through ``eav_filter``, then pass to the ``models.Manager`` get method. ''' - return super(self.__class__, self).get(*args, **kwargs) + return super().get(*args, **kwargs) diff --git a/tests/data_validation.py b/tests/data_validation.py index 3097db6..4ce36f5 100644 --- a/tests/data_validation.py +++ b/tests/data_validation.py @@ -48,7 +48,7 @@ class DataValidation(TestCase): self.assertEqual(Patient.objects.count(), 0) self.assertEqual(Value.objects.count(), 0) - p = Patient.objects.create(name='Joe', eav__weight=2, eav__age=5) + Patient.objects.create(name='Joe', eav__weight=2, eav__age=5) self.assertEqual(Patient.objects.count(), 1) self.assertEqual(Value.objects.count(), 2) diff --git a/tests/queries.py b/tests/queries.py index 7af10cf..3b3f492 100644 --- a/tests/queries.py +++ b/tests/queries.py @@ -38,10 +38,10 @@ class Queries(TestCase): Patient.objects.get_or_create(name='Bob', eav__age=5) self.assertEqual(Patient.objects.count(), 1) self.assertEqual(Value.objects.count(), 1) - p = Patient.objects.get_or_create(name='Bob', eav__age=5) + Patient.objects.get_or_create(name='Bob', eav__age=5) self.assertEqual(Patient.objects.count(), 1) self.assertEqual(Value.objects.count(), 1) - p = Patient.objects.get_or_create(name='Bob', eav__age=6) + Patient.objects.get_or_create(name='Bob', eav__age=6) self.assertEqual(Patient.objects.count(), 2) self.assertEqual(Value.objects.count(), 2)