The attached patch modifies activemapper.Objectstore to do the
containment bit (which *does* resolve the initial issue I was having);
adds more extensive proxying, makes assignmapper go through
get_session() (is that valid for other context objects?), and otherwise
puts things in a state where they seem to Work For Me.
That said, I don't trust this code much: The test suite seems to be
extremely nonfunctional ATM, in that a great many of the tests fail with
OperationalErrors in that tables they refer to aren't being created, so
I can't trivially find out what I broke. (The same thing happens after a
"svn revert", so the massive failure in the test suite appears not to be
my fault).
Index: lib/sqlalchemy/schema.py
===================================================================
--- lib/sqlalchemy/schema.py (revision 1679)
+++ lib/sqlalchemy/schema.py (working copy)
@@ -710,12 +710,12 @@
self.__engines[engine_or_url] = engine_or_url
self.context._engine = engine_or_url
def is_bound(self):
- return self.context._engine is not None
+ return hasattr(self.context, '_engine') and self.context._engine is not None
def dispose(self):
"""disposes all Engines to which this DynamicMetaData has been connected."""
for e in self.__engines.values():
e.dispose()
- engine=property(lambda s:s.context._engine)
+ engine=property(lambda s:hasattr(s.context, '_engine') and s.context._engine or None)
class SchemaVisitor(sql.ClauseVisitor):
"""defines the visiting for SchemaItem objects"""
Index: lib/sqlalchemy/ext/assignmapper.py
===================================================================
--- lib/sqlalchemy/ext/assignmapper.py (revision 1679)
+++ lib/sqlalchemy/ext/assignmapper.py (working copy)
@@ -3,13 +3,13 @@
def monkeypatch_query_method(ctx, class_, name):
def do(self, *args, **kwargs):
- query = class_.mapper.query(session=ctx.current)
+ query = class_.mapper.query(session=ctx.get_session())
return getattr(query, name)(*args, **kwargs)
setattr(class_, name, classmethod(do))
def monkeypatch_objectstore_method(ctx, class_, name):
def do(self, *args, **kwargs):
- session = ctx.current
+ session = ctx.get_session()
if name == "flush":
# flush expects a list of objects
self = [self]
Index: lib/sqlalchemy/ext/activemapper.py
===================================================================
--- lib/sqlalchemy/ext/activemapper.py (revision 1679)
+++ lib/sqlalchemy/ext/activemapper.py (working copy)
@@ -19,12 +19,23 @@
#
# thread local SessionContext
#
-class Objectstore(SessionContext):
- def __getattr__(self, key):
- return getattr(self.current, key)
+class Objectstore(object):
+
+ def __init__(self, *args, **kwargs):
+ self._context = SessionContext(*args, **kwargs)
+
+ def __getattr__(self, name):
+ return getattr(self._context.current, name)
+
def get_session(self):
- return self.current
+ return self._context.current
+ def _get_mapper_extension(self):
+ return self._context.mapper_extension
+ mapper_extension = property(_get_mapper_extension,
+ doc="""get a mapper extension that implements get_session using this context""")
+
+
objectstore = Objectstore(create_session)
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