Actually, I think the problem here is that ObjectStore extends  
SessionContext but it proxies all attribute access to the current  
session. I was actually surprised that the implementation of  
ObjectStore.__getattr__ even works that way (the reasons for my  
suspicions are a bit convoluted so I won't go into detail here).

I think we should change ObjectStore to use containment rather than  
extension. Here's an alternate impl that should work (untested):

class ObjectStore(object):

     def __init__(self, *args, **kwargs):
         self._context = SessionContext(*args, **kwargs)

     def __getattr__(self, name):
         return getattr(self._context.current, name)

This makes ObjectStore a proxy to the thread-local session  
(objectstore is what session evolved from) rather than both a session- 
proxy and a SessionContext at the same time.

~ Daniel


On Jun 30, 2006, at 12:35 PM, Michael Bayer wrote:

> take a look at SessionContext (source code as well as docs on the
> site).  "current" is a property accessor that hits a registry
> function; it creates the session via a callable function passed to
> its constructor.  there should never be a case where no session is
> available since it knows how to create one if needed.
>
>
> On Jun 30, 2006, at 12:11 PM, Charles Duffy wrote:
>
>> After seeing some infinite-recursion issues, I modified
>> activemapper.Objectstore as follows:
>>
>> class Objectstore(SessionContext):
>>      def __getattr__(self, key):
>>          assert hasattr(self, 'current'), 'No session-specific  
>> context
>> object available'
>>          return getattr(self.current, key)
>>      def get_session(self):
>>          return self.current
>>
>> I'm now seeing the following exception:
>>
>> Traceback (most recent call last):
>>    File
>> "/pkgs/Python-2.4.2/lib/python2.4/site-packages/CherryPy-2.2.1-
>> py2.4.egg/cherrypy/_cpserver.py",
>> line 78, in _start
>>      Engine._start(self)
>>    File
>> "/pkgs/Python-2.4.2/lib/python2.4/site-packages/CherryPy-2.2.1-
>> py2.4.egg/cherrypy/_cpengine.py",
>> line 108, in _start
>>      func()
>>    File "/home/ccd/VC/turbogears/turbogears/startup.py", line 222, in
>> startTurboGears
>>      ext.start_extension()
>>    File "/home/ccd/VC/turbogears/turbogears/visit/api.py", line  
>> 64, in
>> start_extension
>>      _manager= _create_visit_manager( timeout )
>>    File "/home/ccd/VC/turbogears/turbogears/visit/api.py", line  
>> 47, in
>> _create_visit_manager
>>      plugin= entrypoint.load()
>>    File
>> "/pkgs/Python-2.4.2/lib/python2.4/site-packages/setuptools-0.6a11-
>> py2.4.egg/pkg_resources.py",
>> line 1830, in load
>>      entry = __import__(self.module_name, globals(),globals(),
>> ['__name__'])
>>    File "/home/ccd/VC/turbogears/turbogears/visit/savisit.py", line
>> 64, in ?
>>      class TG_Visit(ActiveMapper):
>>    File "/home/ccd/VC/sqlalchemy/lib/sqlalchemy/ext/activemapper.py",
>> line 229, in __init__
>>      assign_mapper(objectstore, cls, cls.table)
>>    File "/home/ccd/VC/sqlalchemy/lib/sqlalchemy/ext/assignmapper.py",
>> line 31, in assign_mapper
>>      extension = ctx.mapper_extension
>>    File "/home/ccd/VC/sqlalchemy/lib/sqlalchemy/ext/
>> sessioncontext.py",
>> line 39, in _get_mapper_extension
>>      return self._extension
>>    File "/home/ccd/VC/sqlalchemy/lib/sqlalchemy/ext/activemapper.py",
>> line 24, in __getattr__
>>      assert hasattr(self, 'current'), 'No session-specific context
>> object available'
>> AssertionError: No session-specific context object available
>>
>>
>> So... somehow, I'm not getting a current object in my Objectstore.  
>> How
>> and where is this supposed to be created?
>>
>>
>> Using Tomcat but need to do more? Need to support web services,
>> security?
>> Get stuff done quickly with pre-integrated technology to make your
>> job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache
>> Geronimo
>> http://sel.as-us.falkag.net/sel?
>> cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> Sqlalchemy-users mailing list
>> Sqlalchemy-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>
>
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to