Using Pylons 1.0. We have a simple SQLAlchemy object related to
authentication for which we were doing a query on every page. We
figure we'd play around with Beaker/Memcached and see if we could
pickle the object up and save a teensy bit of load on the database.

In a peice of middlware that we wrote, we attempt to load the object
out of Beaker's cache, add it to the SQLAlchemy session, and continue
on our way. If its not in the cache, we expunge it from the session,
put it in the cache, and then re-add it to the session.

This all works well, as long as the app does not restart. If the app
restarts (but memcached is not flushed) we get SQLAlchemy errors when
trying to add the object to the session. Note that this is all
happening in middleware, before the Pylons app has started handling
the request:

  File "/Users/dave/om/trunk/OpenMile/openmile/model/authtoken.py",
line 122, in forToken
    meta.Session.add(at)
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/scoping.py", line 127, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/session.py", line 1089, in
add
    self._save_or_update_state(state)
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/session.py", line 1099, in
_save_or_update_state
    self._cascade_save_or_update(state)
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/session.py", line 1105, in
_cascade_save_or_update
    for state, mapper in _cascade_unknown_state_iterator('save-
update', state, halt_on=lambda c:c in self):
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/session.py", line 1561, in
_cascade_unknown_state_iterator
    for (o, m) in mapper.cascade_iterator(cascade, state, **kwargs):
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/mapper.py", line 1207, in
cascade_iterator
    instance, instance_mapper, corresponding_state  = iterator.next()
  File "/Users/dave/om/trunk/lib/python2.5/site-packages/
SQLAlchemy-0.5.7-py2.5.egg/sqlalchemy/orm/properties.py", line 686, in
cascade_iterator
    mapper = self.mapper.primary_mapper()
AttributeError: 'RelationProperty' object has no attribute 'mapper'


We can make this problem go away one of two ways: 1) flush the cache
(not desirable.) 2) Issue a request to the server that does not invoke
the caching code. After we issue a single, quick working request,
subsequent requests work fine everything is happy.

It seems to me that this is a bug. When I start the server, shouldn't
Pylons have SQLAlchemy fully set up? What magic is the first request
doing that is being missed?

-- 
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.

Reply via email to