Well, it appears I have answered my own question and, yes, it was a
SQLAlchemy issue.  I resolved the problem by explicitly compiling the
mapping at the end of the model initialization:

manager_mapper = orm.mapper(Manager, manager_table, ... etc.
... (all other dependent mappers)

manager_mapper.compile()

My extremely vague understanding of what is going on is that if you
are explicitly using the SQLAlchemy API to retrieve the pickled object
then compiling is done implicitly but if the API is not used then the
compiling is not done and you run into troubles.  I am not sure how
the beaker session is trying to interact with the object that causes
the problem versus my own testing of interacting with the pickled
object being successful but compiling is the answer.

If someone has a more robust explanation I would be very interested to
hear it.


On Oct 21, 10:08 pm, rootsmith <ke...@rootsmith.ca> wrote:
> Hi,
>
> I have a pylons application using file based beaker sessions (not to
> be confused with SQLAlchemy 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.
>
> Now I know this sounds like a beaker session problem but it is failing
> when it is making a call to the SQLAlchemy object.  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 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to