google app engine - Pickling on GAE ndb -


i trying pickle , unpickle structured data ndb.pickleproperty() property so:

month = monthrecord.get_or_insert(month_yr_str, parent=ndb.key('type','grocery'), record=pickle.dumps(defaultdict(list_list))) names_dict = pickle.loads(month.record) # unpickle updating # ...                                   # modifications on names_dict month.record = pickle.dumps(names_dict) # pickle month.put()                             # commit changes 

where model monthrecord defined as:

class monthrecord(ndb.model):     record = ndb.pickleproperty() # {name: [[date&time],[expenses]]} 

and list_list as:

def list_list(): # placeholder function needed pickle @ module level     return [[],[]] 

the first run works fine (where insert case hit in get_or_insert, creating new monthrecord entity). however, during succeeding runs (i.e. new expenses within current month recorded) following error occurs:

traceback (most recent call last):   file "c:\gae_projects\qb_lite\fin.py", line 31, in update_db     names_dict = pickle.loads(month.record)   file "c:\python27\lib\pickle.py", line 1382, in loads     return unpickler(file).load()   file "c:\python27\lib\pickle.py", line 858, in load     dispatch[key](self)   file "c:\python27\lib\pickle.py", line 1133, in load_reduce     value = func(*args) typeerror: __init__() takes 4 arguments (1 given) 

any ideas cause of error?

you don't have pickle objects, handled pickleproperty.

instead of:

month = monthrecord.get_or_insert(     month_yr_str,     parent=ndb.key('type','grocery'),     record=pickle.dumps(defaultdict(list_list))) 

do:

month = monthrecord.get_or_insert(     month_yr_str,     parent=ndb.key('type','grocery'),     record=defaultdict(list_list)) 

pickling , unpickling taken care of internally.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -