This is long, but my primary question is "How the heck do I save a
picklable copy of POST data, specifically to cache it for use in a
inclusion tag, without manually extracting the data into a normal
dict?"

My tag has a form that posts to a single view that may not be the
current one.  I want the view to which the form posts to pass the form
data via cache if validation fails, to show errors on the next page
view.  I know this is tricky, but it all works fine except for getting
the posted data easily.  If I extract the vals and put them in a dict
and cache that everything works as planned.

I've been trying to cache a request.POST object.  This has caused
pain.  The QueryDict object apparently does not pickle nicely.  I get
an error on cache fetch saying self._mutable does not exists, from
this method call.

    def _assert_mutable(self):
        if not self._mutable:
            raise AttributeError, "This QueryDict instance is
immutable"

Ok, no problem.  I'll just cache the form since that's really what I
wanted anyway. That also fails when fetching from cache.

     60   def __setitem__(self, key, value):
     61         dict.__setitem__(self, key, value)
----> 62         if key not in self.keyOrder:
     63             self.keyOrder.append(key)
     64

AttributeError: 'SortedDictFromList' object has no attribute
'keyOrder'

Ok, fine.  I'll tried just caching the form.data. Which worked! Kind
of. Note that AFTER fetching from the cache the multivalue list is now
part of another list.  list(list).  Cache and fetch again and we have
list(list(list)).  Now it's just taunting me:

In [11]: m=MultiValueDict()
In [12]: m['Testing']
In [13]: m['Testing']='Single element in a single list'
In [14]: cache.set('mvd',m)
In [15]: mc=cache.get('mvd')
In [16]: mc
Out[16]: <MultiValueDict: {'Testing': [['Single element in a single
list']]}>
In [17]: m
Out[17]: <MultiValueDict: {'Testing': ['Single element in a single
list']}>
In [18]: cache.set('mvd',mc)
In [19]: mc=cache.get('mvd')
In [20]: mc
Out[20]: <MultiValueDict: {'Testing': [[['Single element in a single
list']]]}>

After much poking about, that problem is right here in cache/backends/
filebased.py, CacheClass.set() method.

pickle.dump(value, f, 2).

Protocol 2 gives MultiValueDict funkyness.  Protocol 1 works fine.

I can work around the current problem, but it worries me how many
other things are not cache/session storable?  It makes sense that some
things really can't be peristed, but data objects I thought would be
ok... but some don't seem to be.


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

Reply via email to