#14515: Can't pickle ValueQuerySet if query references fields, which aren't on 
the
same model.
---------------------------------------------------+------------------------
          Reporter:  apollo13                      |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  1.2   
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  0     
        Needs_docs:  0                             |   Needs_tests:  0     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by russellm):

  * stage:  Unreviewed => Accepted
  * milestone:  1.3 =>

Old description:

> This will work during pickle.dumps: http://paste.pocoo.org/show/278047/
> 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'] }}}
> (http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L176);
> during loads it won't find Page.deleted etc… (full traceback:
> http://paste.pocoo.org/show/278050/)

New description:

 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'] }}}
 
(http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L176);
 during loads it won't find Page.deleted etc… Full traceback:
 {{{
 Traceback (most recent call last):
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/application.py",
 line 52, in __call__
     return self.app(environ, start_response)
   File "/home/florian/.virtualenvs/inyoka/lib/python2.6/site-
 packages/Django-1.2.3-py2.6.egg/django/core/handlers/wsgi.py", line 241,
 in __call__
     response = self.get_response(request)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/application.py",
 line 88, in get_response
     return callback(request, *args, **kwargs)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/views.py",
 line 60, in show_page
     return PAGE_ACTIONS[action or 'show'](request, normalized_name)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/acl.py", line
 217, in oncall
     return f(request, name)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/http.py",
 line 40, in proxy
     rv = f(request, *args, **kwargs)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/actions.py",
 line 99, in do_show
     return do_missing_page(request, name)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/http.py",
 line 40, in proxy
     rv = f(request, *args, **kwargs)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/actions.py",
 line 199, in do_missing_page
     } for x in sorted(Page.objects.get_similar(name))],
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/models.py",
 line 346, in get_similar
     self._get_object_list(False) if not x[1]], n)]
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/wiki/models.py",
 line 200, in _get_object_list
     pagelist = request_cache.get(key)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/cache.py",
 line 68, in get
     val = self.real_cache.get(key)
   File "/home/florian/.virtualenvs/inyoka/inyoka/inyoka/utils/cache.py",
 line 118, in get
     self.cache.get(key))
   File "/home/florian/.virtualenvs/inyoka/lib/python2.6/site-
 packages/Werkzeug-0.6.2-py2.6.egg/werkzeug/contrib/cache.py", 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/query.py", 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/options.py", line 273, in
 get_field
     raise FieldDoesNotExist('%s has no field named %r' %
 (self.object_name, name))
 FieldDoesNotExist: Page has no field named 'deleted'
 }}}

Comment:

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

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14515#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to