Opened 8 years ago

Closed 3 years ago

Last modified 3 years ago

#14515 closed Bug (fixed)

Can't pickle ValueQuerySet if query references fields, which aren't on the same model.

Reported by: Florian Apolloner Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Russell Keith-Magee)

This will work during pickle.dumps:

            pagelist = Page.objects.all().select_related('last_rev')\
                .order_by('name').values_list('name', 'last_rev__deleted',
                    'last_rev__id', 'last_rev__attachment__id')
            # force a list, can't pickle ValueQueryset that way
            pagelist = list(pagelist)
            request_cache.set(key, pagelist, 10000)

but will fail when I run loads.

The reason is that __getstate__ of ValueQueryset puts (in this case) ['name', 'deleted', 'id', 'id'] into obj_dict['search_fields'] (; during loads it won't find Page.deleted etc… Full traceback:

Traceback (most recent call last):
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/", line 52, in __call__
    return, start_response)
  File "/home/florian/.virtualenvs/inyoka/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/handlers/", line 241, in __call__
    response = self.get_response(request)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/", line 88, in get_response
    return callback(request, *args, **kwargs)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/", line 60, in show_page
    return PAGE_ACTIONS[action or 'show'](request, normalized_name)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/", line 217, in oncall
    return f(request, name)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/", line 40, in proxy
    rv = f(request, *args, **kwargs)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/", line 99, in do_show
    return do_missing_page(request, name)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/", line 40, in proxy
    rv = f(request, *args, **kwargs)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/", line 199, in do_missing_page
    } for x in sorted(Page.objects.get_similar(name))],
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/", line 346, in get_similar
    self._get_object_list(False) if not x[1]], n)]
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/", line 200, in _get_object_list
    pagelist = request_cache.get(key)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/", line 68, in get
    val = self.real_cache.get(key)
  File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/", line 118, in get
  File "/home/florian/.virtualenvs/inyoka/lib/python2.6/site-packages/Werkzeug-0.6.2-py2.6.egg/werkzeug/contrib/", line 229, in get
    return loads(value)
  File "/home/florian/.virtualenvs/inyoka/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/db/models/sql/", line 200, in __setstate__
    for name in obj_dict['select_fields']
  File "/home/florian/.virtualenvs/inyoka/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/db/models/", line 273, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, name))
FieldDoesNotExist: Page has no field named 'deleted'

Change History (10)

comment:1 Changed 8 years ago by Florian Apolloner

Component: UncategorizedDatabase layer (models, ORM)

comment:2 Changed 8 years ago by Florian Apolloner

milestone: 1.3

comment:3 Changed 8 years ago by Alex Gaynor

Description: modified (diff)

Cleaned up the formatting.

comment:4 Changed 7 years ago by Russell Keith-Magee

Description: modified (diff)
milestone: 1.3
Triage Stage: UnreviewedAccepted

Removed references to a pastebin. Trac provides perfectly adequate source code quoting tools, and has no risk of expiring, getting deleted etc.

comment:5 Changed 7 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:6 Changed 6 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 6 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:8 Changed 6 years ago by david@…

Is there a workaround for this?

comment:9 Changed 3 years ago by Claude Paroz

Resolution: fixed
Status: newclosed

This issue seems to be fixed in current code. I'll complement a test for confirmation.

comment:10 Changed 3 years ago by Claude Paroz <claude@…>

In fae551d765bc24103ce1b9782aa264246abfa2b8:

Complemented pickle test for ValuesQuerySet with related field

Refs #14515.

Note: See TracTickets for help on using tickets.
Back to Top