From d0d8a4827e922b0404876d6264bc15f3c8e3e2ef Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 29 Sep 2012 23:20:37 -0500 Subject: [PATCH] pickle.dumps(db(query).select() now always works and loads restore the full object (almost) --- VERSION | 2 +- gluon/dal.py | 46 +++++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/VERSION b/VERSION index ae03788d..92895471 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.9 (2012-09-29 22:33:02) dev +Version 2.0.9 (2012-09-29 23:20:28) dev diff --git a/gluon/dal.py b/gluon/dal.py index 03efad23..5f343bb6 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -1947,7 +1947,7 @@ class BaseAdapter(ConnectionPool): db._referee_name % dict( table=rfield.tablename,field=rfield.name) if referee_link and not referee_link in colset: - colset[referee_link] = Set(db,rfield == id) + colset[referee_link] = LazySet(rfield,id) else: if not '_extra' in new_row: new_row['_extra'] = Row() @@ -6445,15 +6445,6 @@ class Row(object): del d[k] return d -def Row_unpickler(data): - return Row(cPickle.loads(data)) - -def Row_pickler(data): - return Row_unpickler, (cPickle.dumps(data.as_dict(datetime_to_str=False)),) - -copy_reg.pickle(Row, Row_pickler, Row_unpickler) - - ################################################################################ # Everything below should be independent of the specifics of the database # and should work for RDBMs and some NoSQL databases @@ -6685,8 +6676,6 @@ class DAL(object): if hasattr(self,'_adapter'): return - print 'in init' - if not decode_credentials: credential_decoder = lambda cred: cred else: @@ -8849,10 +8838,12 @@ class Set(object): class RecordUpdater(object): def __init__(self, colset, table, id): - self.colset, self.table, self.id = colset, table, id + self.colset, self.db, self.tablename, self.id = \ + colset, table._db, table._tablename, id def __call__(self, **fields): - colset, table, id = self.colset, self.table, self.id + colset, db, tablename, id = self.colset, self.db, self.tablename, self.id + table = db[tablename] newfields = fields or dict(colset) for fieldname in newfields.keys(): if not fieldname in table.fields or table[fieldname].type=='id': @@ -8863,9 +8854,23 @@ class RecordUpdater(object): class RecordDeleter(object): def __init__(self, table, id): - self.table, self.id = table,id + self.db, self.tablename, self.id = table._db, table._tablename, id def __call__(self): - return self.table._db(self.table._id==self.id).delete() + return self.db(self.db[self.tablename]._id==self.id).delete() + +class LazySet(object): + def __init__(self, field, id): + self.db, self.tablename, self.fieldname, self.id = \ + field.db, field._tablename, field.name, id + def _getset(self): + query = self.db[self.tablename][self.fieldname]==self.id + return Set(self.db,query) + def select(self,*a,**b): + return self._getset().select(*a,**b) + def delete(self,*a,**b): + return self._getset().update(*a,**b) + def __call__(self,*a,**b): + return self._getset()(*a,**b) class VirtualCommand(object): @@ -9242,15 +9247,6 @@ class Rows(object): import gluon.contrib.simplejson as simplejson return simplejson.dumps(items) -# def Rows_unpickler(data): -# return cPickle.loads(data) -# -# def Rows_pickler(data): -# return Rows_unpickler, \ -# (cPickle.dumps(data.as_list(storage_to_dict=False, -# datetime_to_str=False)),) -# copy_reg.pickle(Rows, Rows_pickler, Rows_unpickler) - ################################################################################ # dummy function used to define some doctests