It appears I have answered my own question. If I explicitly compile the mapper of the object that is in the beaker session on the model initialization then it resolves the problem. The only problem left is explaining why this is so?
What strangeness is the beaker session up to that it gets around interacting with the SQLAlchemy API but still manages to interact with the object? From what I understand of SQLAlchemy, the second you interact with a mapped object it should implicitly compile the mapper if it has not already done so. On Oct 21, 10:16 pm, rootsmith <[email protected]> wrote: > Hi, > > Disclaimer: I have kinda cross posted this over at the SQLAlchemy > mailing list in an effort to trace down the corner of pylons that may > be responsible for the following behaviour: > > I have a pylons application using file based beaker sessions. I > retrieve a mapped object from the database, detach it from the > SQLAlchemy Session like so: > > Session.expunge(object) > > and save it to the beaker session (basically pickling it to a file.) > like so: > > session['user'] = user > session.save() > > If I restart the server and retrieve the pickled object from the > session, merge it back into the SQLAlchemy Session everything seems to > be fine. > > user = Session.merge(session['user'], dont_load=True) > > But then somewhere in the beaker session middleware something goes > awry before it completes the call to the controller. It is so deep in > the beaker session code and/or SQLAlchemy black magicness that I am > having a hard time figuring out what is going on. I don't know if > this should be expected behaviour or I have done something wrong or > there is a problem with beaker and/or SQLAlchemy. > > Here is the stack trace: > > URL:http://127.0.0.1:5000/ > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/ > WebError-0.10.1-py2.6.egg/weberror/evalexception.py', line 431 in > respond > app_iter = self.application(environ, detect_start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Paste-1.7.2- > py2.6.egg/paste/recursive.py', line 80 in __call__ > return self.application(environ, start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/middleware.py', line 73 in __call__ > return self.app(environ, start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/middleware.py', line 152 in __call__ > return self.wrap_app(environ, session_start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Routes-1.10.3- > py2.6.egg/routes/middleware.py', line 130 in __call__ > response = self.app(environ, start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Pylons-0.9.7- > py2.6.egg/pylons/wsgiapp.py', line 125 in __call__ > response = self.dispatch(controller, environ, start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Pylons-0.9.7- > py2.6.egg/pylons/wsgiapp.py', line 324 in dispatch > return controller(environ, start_response) > File '/Users/kevin/Documents/workspace/ryzoe/ryzoe/lib/base.py', line > 54 in __call__ > return WSGIController.__call__(self, environ, start_response) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Pylons-0.9.7- > py2.6.egg/pylons/controllers/core.py', line 284 in __call__ > return response(environ, self.start_response) > File 'build/bdist.macosx-10.6-universal/egg/webob/__init__.py', line > 2182 in __call__ > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/middleware.py', line 146 in session_start_response > session.persist() > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/session.py', line 600 in persist > self._session().save() > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/session.py', line 293 in save > self.namespace.release_write_lock() > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/container.py', line 149 in release_write_lock > self.close(checkcount=True) > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/container.py', line 172 in close > self.do_close() > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/Beaker-1.4.1- > py2.6.egg/beaker/container.py', line 536 in do_close > cPickle.dump(self.hash, fh) > File '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/copy_reg.py', line 84 in _reduce_ex > dict = getstate() > File '/Users/kevin/mydevenv/lib/python2.6/site-packages/ > SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/collections.py', line 607 in > __getstate__ > return {'key': self.attr.key, > AttributeError: 'NoneType' object has no attribute 'key' > > Here is the mapper of the object that is pickled: > > orm.mapper(Manager, manager_table, inherits=User, > polymorphic_identity='manager', > properties={'residences': relation(Residence, > lazy=False, > > back_populates='manager')}) > > In the end, I can always just flush the cache (delete the files) on a > server restart but something is striking me odd as to why this is > failing. I want to make sure I don't have some flawed understanding > of something somewhere. > > Any help would be greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
