sure, the threadlocal mod and the activemapper mod both make their own SessionContext, both of which get associated with the mapper for Foo, and then they are conflicting. they are currently not compatible. while I could improve the behavior of MapperExtension so that the SessionContext set up by ActiveMapper takes precedence over the more global one set up by threadlocal, that doesnt answer the question why you are using both modules at the same time. are you going to mix ActiveMapper classes with non-activemapper classes, and want a single objectstore.flush() to save them all ? if we would like to say that, if one uses the ActiveMapper extension, then that automatically loads the "threadlocal" mod in all cases, we can go with that, although im not terribly comfortable with making that assumption. a more complex approach would involve the ActiveMapper extension detecting if the threadlocal mod is already installed, and if so it would swap out its own "objectstore" object for the one used by the threadlocal mod. below is a patch that does this, which forces me to change the threadlocal mod to match the changes you made to ActiveMapper's objectstore. Is there a test condition you can send me that illustrates why it was necessary to have Objectstore no longer subclass SessionContext ? Index: lib/sqlalchemy/ext/activemapper.py =================================================================== --- lib/sqlalchemy/ext/activemapper.py (revision 1681) +++ lib/sqlalchemy/ext/activemapper.py (working copy) @@ -6,6 +6,7 @@ from sqlalchemy.ext.sessioncontext import SessionContext from sqlalchemy.ext.assignmapper import assign_mapper from sqlalchemy import backref as create_backref +import sqlalchemy import inspect import sys @@ -16,20 +17,22 @@ # metadata = DynamicMetaData("activemapper") -# -# thread local SessionContext -# -class Objectstore(object): +try: + objectstore = sqlalchemy.objectstore +except AttributeError: + # + # thread local SessionContext + # + class Objectstore(object): - def __init__(self, *args, **kwargs): - self._context = SessionContext(*args, **kwargs) + def __init__(self, *args, **kwargs): + self._context = SessionContext(*args, **kwargs) - def __getattr__(self, name): - return getattr(self._context.current, name) + def __getattr__(self, name): + return getattr(self._context.current, name) + objectstore = Objectstore(create_session) -objectstore = Objectstore(create_session) - # # declarative column declaration - this is so that we can infer the colname # @@ -224,9 +227,11 @@ # check for inheritence if hasattr(bases[0], "mapping"): cls._base_mapper= bases[0].mapper + print "assign mpaper with context", objectstore._context assign_mapper(objectstore._context, cls, cls.table, inherits=cls._base_mapper) else: + print "assign mpaper with context", objectstore._context assign_mapper(objectstore._context, cls, cls.table) cls.relations = relations ActiveMapperMeta.classes[clsname] = cls Index: lib/sqlalchemy/mods/threadlocal.py =================================================================== --- lib/sqlalchemy/mods/threadlocal.py (revision 1681) +++ lib/sqlalchemy/mods/threadlocal.py (working copy) @@ -22,24 +22,25 @@ __all__ = ['Objectstore', 'assign_mapper'] -class Objectstore(SessionContext): - def __getattr__(self, key): - return getattr(self.current, key) - def get_session(self): - return self.current +class Objectstore(object): + def __init__(self, *args, **kwargs): + self._context = SessionContext(*args, **kwargs) + def __getattr__(self, name): + return getattr(self._context.current, name) + def assign_mapper(class_, *args, **kwargs): - assignmapper.assign_mapper(objectstore, class_, *args, **kwargs) + assignmapper.assign_mapper(objectstore._context, class_, *args, **kwargs) objectstore = Objectstore(Session) def install_plugin(): sqlalchemy.objectstore = objectstore - global_extensions.append(objectstore.mapper_extension) + global_extensions.append(objectstore._context.mapper_extension) engine.default_strategy = 'threadlocal' sqlalchemy.assign_mapper = assign_mapper def uninstall_plugin(): engine.default_strategy = 'plain' - global_extensions.remove(objectstore.mapper_extension) + global_extensions.remove(objectstore._context.mapper_extension) install_plugin() On Jul 8, 2006, at 9:28 AM, Charles Duffy wrote:
|
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