Hi all.
Environment:
Ubuntu Hardy, python2.5, sqlalchemy 0.5.2
I need to store serialized model in memcached.
If I store model to memcached and get this model from cache in the same
process everything looks fine.
But if I try to get model from cache in another process, I would have an
exception AttributeError. For example I try to unserialize model from
pickle string in ipython:
in [2]: Session = sessionmaker(autoflush=False, autocommit=False,
expire_on_commit=False)
In [3]: s = Session(bind=dbswitch.pool.getRootMaster())
No handlers could be found for logger "aux"
In [4]: m =
s.query(reload(Models).Account).filter(Account.login=='msahnov').first()
In [7]: m.login
Out[7]: 'msahnov'
In [8]: import cPickle
In [9]: cPickle.loads(cPickle.dumps(m)).login
Out[9]: 'msahnov'
In [10]: cPickle.dumps(m)
Out[10]:
"ccopy_reg\n_reconstructor\np1\n(cModels\nAccount\np2\nc__builtin__\nobject\np3\nNtRp4\n(dp5\nS'person_id'\np6\nL1120000000016603L\nsS'login'\np7\nS'msahnov'\np8\nsS'_sa_instance_state'\np9\ng1\n(csqlalchemy.orm.identity\nIdentityManagedState\np10\ng3\nNtRp11\n(dp12\nS'modified'\np13\nI00\nsS'committed_state'\np14\n(dp15\nsS'instance'\np16\ng4\nsS'callables'\np17\n(dp18\nsS'parents'\np19\n(dp20\nsS'key'\np21\n(g2\n(L1120000000016603L\nttp22\nsS'expired_attributes'\np23\nc__builtin__\nfrozenset\np24\n((ltRp25\nsS'expired'\np26\nI00\nsS'pending'\np27\n(dp28\nsbsb."
Do you really want to exit ([y]/n)?
In [1]: import cPickle
In [2]:
cPickle.loads("ccopy_reg\n_reconstructor\np1\n(cModels\nAccount\np2\nc__builtin__\nobject\np3\nNtRp4\n(dp5\nS'person_id'\np6\nL1120000000016603L\nsS'login'\np7\nS'msahnov'\np8\nsS'_sa_instance_state'\np9\ng1\n(csqlalchemy.orm.identity\nIdentityManagedState\np10\ng3\nNtRp11\n(dp12\nS'modified'\np13\nI00\nsS'committed_state'\np14\n(dp15\nsS'instance'\np16\ng4\nsS'callables'\np17\n(dp18\nsS'parents'\np19\n(dp20\nsS'key'\np21\n(g2\n(L1120000000016603L\nttp22\nsS'expired_attributes'\np23\nc__builtin__\nfrozenset\np24\n((ltRp25\nsS'expired'\np26\nI00\nsS'pending'\np27\n(dp28\nsbsb.").login
<PersonsModel.Person object at 0x2395110> <class 'PersonsModel.Person'> None
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'> Traceback (most recent call last)
/home/msahnov/accounts/<ipython console> in <module>()
/var/lib/python-support/python2.5/sqlalchemy/orm/attributes.py in
__get__(self, instance, owner)
158 if instance is None:
159 return self
--> 160 return self.impl.get(instance_state(instance))
161
162 class _ProxyImpl(object):
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'get'
If I merge unserialized object with new session - it would work fine, but I
think, that it would make some queries in database.
How can I work with unserialized detached model?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.