W1ldPo1nter / django-queryable-properties

Write Django model properties that can be used in database queries.
BSD 3-Clause "New" or "Revised" License
71 stars 1 forks source link

AttributeError: 'super' object has no attribute '__iter__' #16

Closed Anton-Shutik closed 6 months ago

Anton-Shutik commented 6 months ago

Hi, Thanks for great django addon!

I have models like this:


class VariantManager(QueryablePropertiesManagerMixin, models.Manager):
    pass

class Variant(models.Model):
    name = models.CharField()

    objects = VariantManager()

class StockLevel(models.Model):
    variant = models.ForeignKey("Variant")

And exception can be raised with:

variants = Variant.objects.filter(id=1)
stocklevels = StockLevel.objects.filter(variant__in=variants)

StackTrace:

  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/query.py", line 941, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1416, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1435, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1343, in build_filter
    self.check_related_objects(join_info.final_field, value, join_info.opts)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1172, in check_related_objects
    for v in value:
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/queryable_properties/query.py", line 110, in __iter__
    for row in super(QueryablePropertiesQueryMixin, self).__iter__():
AttributeError: 'super' object has no attribute '__iter__'
django==3.2.23
django-queryable-properties==1.9.1

Looks like the issue when Im filtering on a FK that has QueryableManager.

Do you have any idea what can be wrong here ?

Thanks in advance

W1ldPo1nter commented 6 months ago

Thanks for the report.

I was able to reconstruct your case and identify a bug - it seems like using querysets with the queryable property extensions in __in subqueries was broken when support for raw queries was added. I'll try to implement a fix and publish a new version soon.

In the meantime, you could try to use django-queryable-properties==1.8.5 as that was the last version without support for raw queries, so it shouldn't contain the bug.

W1ldPo1nter commented 6 months ago

The bug should now be fixed in version 1.9.2, which was just released.

Anton-Shutik commented 6 months ago

Yeah, works for me! Thank you so much for quick fix!