akaariai / django-reverse-unique

A ReverseUnique model field implementation for Django
BSD 3-Clause "New" or "Revised" License
22 stars 5 forks source link

prefetch_related doesn't work #3

Open gavinwahl opened 10 years ago

gavinwahl commented 10 years ago

Should you be able to include a ReverseUnique field in prefetch_related? Something like Lang.objects.all().prefetch_related('articletranslation_set__article__active_translation'). Currently this raises an error:

  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 96, in __iter__
    self._fetch_all()
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 856, in _fetch_all
    self._prefetch_related_objects()
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 517, in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, self._prefetch_related_lookups)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 1598, in prefetch_related_objects
    obj_list, additional_prl = prefetch_one_level(obj_list, prefetcher, attr)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 1697, in prefetch_one_level
    prefetcher.get_prefetch_queryset(instances)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 277, in get_prefetch_queryset
    qs = self.get_queryset(instance=instances[0]).filter(**query)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 590, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 608, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1198, in add_q
    clause = self._add_q(where_part, used_aliases)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1232, in _add_q
    current_negated=current_negated)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1100, in build_filter
    allow_explicit_fk=True)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1351, in setup_joins
    names, opts, allow_many, allow_explicit_fk)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1274, in names_to_path
    "Choices are: %s" % (name, ", ".join(available)))
FieldError: Cannot resolve keyword '+' into field. Choices are: abstract, article, body, id, lang, title
akaariai commented 10 years ago

All I can say is pull requests welcome.