Skip to content

'VersionSlugFilter' object is not iterable #2495

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

Closed
NikitaEgorov opened this issue Nov 14, 2016 · 9 comments · Fixed by #2499 or #2501
Closed

'VersionSlugFilter' object is not iterable #2495

NikitaEgorov opened this issue Nov 14, 2016 · 9 comments · Fixed by #2499 or #2501

Comments

@NikitaEgorov
Copy link

Details

  • Project URL: local
  • Build URL (if applicable): local
  • Read the Docs username (if applicable): local

Expected Result

Open new project

A description of what you wanted to happen
Fresh ReadTheDocs installation
Try to open exists or new project

Actual Result

TypeError at /projects/invoicing/
'VersionSlugFilter' object is not iterable
A description of what actually happened
In template
checkouts/readthedocs.org/readthedocs/templates/core/project_details.html, error at line 35

25


26
27 {{ filter.form }}
28 <input type="submit" value="{% trans "Filter" %}">
29
30

31 {% endcomment %}
32
33

34
@fulopattila122
Copy link

Same here

@fulopattila122
Copy link

Request URL:    http://192.168.81.10:8000/projects/concord/
Django Version: 1.8.3
Exception Type: TypeError
Exception Value:    
'VersionSlugFilter' object is not iterable
Exception Location: /home/vagrant/checkouts/readthedocs.org/readthedocs/projects/templatetags/projects_tags.py in sort_version_aware, line 17
Python Executable:  /usr/bin/python
Python Version: 2.7.9
Python Path:    
['/home/vagrant/checkouts/readthedocs.org',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/pymodules/python2.7',
 '/home/vagrant/checkouts/readthedocs.org']
Server time:    Mon, 14 Nov 2016 05:37:33 -0600

@benjaoming
Copy link
Contributor

I tried this in readthedocs/projects/templatetags/projects_tags.py:

Replacing:

@register.filter
def sort_version_aware(versions):
    """Takes a list of versions objects and sort them using version schemes"""
    return sorted(
        versions,  # <- THIS LINE
        key=lambda version: comparable_version(version.verbose_name),
        reverse=True)

with:

@register.filter
def sort_version_aware(versions):
    """Takes a list of versions objects and sort them using version schemes"""
    return sorted(
        list(versions.qs),  # <- THIS LINE
        key=lambda version: comparable_version(version.verbose_name),
        reverse=True)

However, now there's a new error:

(SNIP)

File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  155.                 values = self.sequence.resolve(context, True)
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django/template/base.py" in resolve
  674.                 new_obj = func(obj, *arg_vals)
File "/home/user/readthedocs.org/readthedocs/projects/templatetags/projects_tags.py" in sort_version_aware
  15.         list(versions.qs),
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django_filters/filterset.py" in qs
  195.             if not self.form.is_valid():
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django_filters/filterset.py" in form
  220.                 for name, filter_ in six.iteritems(self.filters)])
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django_filters/filters.py" in field
  159.                                                label=self.label, widget=self.widget,
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django_filters/filters.py" in fget
  115.                     model, self.name, self.lookup_expr, self.exclude
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django_filters/utils.py" in label_for_filter
  219.     name = verbose_field_name(model, field_name)
File "/home/user/.virtualenvs/rtd/local/lib/python2.7/site-packages/django_filters/utils.py" in verbose_field_name
  179.     return ' '.join(names)

Exception Type: TypeError at /projects/ka-lite/
Exception Value: sequence item 0: expected string, __proxy__ found

...which to me indicates that django-filter is doing stuff that doesn't like lazy ugettext objects.

As a new dev, I'm confused about this application django-filter, what it is, why it's there etc. :) Why not use good old custom managers?

@benjaoming
Copy link
Contributor

If I add names = map(str, names) in django-filters utils.py, things work - so not sure if the issue is upstream or if RTD should replace a lazy gettext with an eager evaluation.

benjaoming added a commit to benjaoming/django-filter that referenced this issue Nov 14, 2016
This fixes an issue here: readthedocs/readthedocs.org#2495

I'm not sure if this is the preferred way of doing things, nor am I sure if this project is 2+3? But hopefully this can assist getting the issue solved... feel free to close this PR and implement your own way :)
@benjaoming
Copy link
Contributor

This issue is also reported here: #2490

I see the same issue on projects/<slug>/builds/:

TypeError
object of type 'BuildFilter' has no len()

@benjaoming
Copy link
Contributor

Btw. it would seem that the more general issue is that the django-filter API has changed: Filter objects are no longer iterable in themselves, you have to use the .qs property.

The change is described in the 1.0 release notes:

http://django-filter.readthedocs.io/en/latest/migration.html#queryset-methods-are-no-longer-proxied

@fulopattila122
Copy link

Myself not being a python dev, most of the discussion is mambo-jumbo ;)
How can I fix it?

@benjaoming
Copy link
Contributor

@fulopattila122 it means if you're running readthedocs locally, then after enabling your virtual env, do this:

pip uninstall django-filter
pip install -r requirements.txt

@fulopattila122
Copy link

@benjaoming Thanks! That just worked!

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

Successfully merging a pull request may close this issue.

3 participants