Hi all,

I'm trying to implement simple object serialization (ala the pickle
module) using JSON.  I'm pretty far along, but having one problem --
serializing a sqlalchemy object through the __reduce__ method produces
a circular reference through the InstanceState object.

pprint of the structures in question:

account.__reduce__():
(<function _reconstructor at 0x42530>,
 (<class 'model.account.Account'>,
  <type 'object'>,
  None),
 {'_comment': None,
  '_description': None,
  '_display_name': u'm',
  '_email': u'[EMAIL PROTECTED]',
  '_email_status': 1L,
  '_entity_name': None,
  '_instance_key': (<class 'model.account.Account'>,
                    (5L,),
                    None),
  '_name_graphic': u'm',
  '_password_hash': u'bar',
  '_sa_session_id': 43005744,
  '_state': <sqlalchemy.orm.attributes.InstanceState object at
0x286f978>,      <---- InstanceState object
  '_status': 1L,
  '_uri': None,
  '_user_name': u'm',
  'account_id': 5L,
  'avatar_exists': False,
  'creation_time': datetime.datetime(2006, 8, 23, 17, 43, 26),
  'modification_time': datetime.datetime(2007, 12, 19, 23, 3, 2),
  'newsletter': False,
  'reviewed': False,
  'site_updates': False})

account._state.__reduce__():
(<function _reconstructor at 0x42530>,
 (<class 'sqlalchemy.orm.attributes.InstanceState'>, <type 'object'>,
None),
 {'committed_state': {'_comment': None,
                      '_description': None,
                      '_display_name': u'm',
                      '_email': u'[EMAIL PROTECTED]',
                      '_email_status': 1L,
                      '_name_graphic': u'm',
                      '_password_hash': u'bar',
                      '_status': 1L,
                      '_uri': None,
                      '_user_name': u'm',
                      'account_id': 5L,
                      'avatar_exists': False,
                      'creation_time': datetime.datetime(2006, 8, 23,
17, 43, 26),
                      'modification_time': datetime.datetime(2007, 12,
19, 23, 3, 2),
                      'newsletter': False,
                      'reviewed': False,
                      'site_updates': False},
  'instance': <model.account.Account object at 0x2971350>,    <---
reference back to Account object
  'modified': False,
  'parents': {}})

So right now, I just break the circular reference the second time I
see the Account object, but this causes problems deserializing since
the InstanceState object is missing some data...

Any thoughts appreciated here...  pickle is able to handle this
structure fine, but I'm not sure exactly what algorithm it uses to do
this...

m

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

Reply via email to