From: Mike Bayer Date: Sun, 27 Jul 2008 16:52:05 +0000 (+0000) Subject: - Added "add()" and "add_all()" to scoped_session X-Git-Tag: rel_0_4_7p1~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80a0abb7a7423f63bbda171da292dc8a18f5ece5;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added "add()" and "add_all()" to scoped_session methods. Workaround for 0.4.7: from sqlalchemy.orm.scoping import ScopedSession,\ instrument setattr( ScopedSession, "add", instrument("add")) setattr( ScopedSession, "add_all", instrument("add_all")) --- diff --git a/CHANGES b/CHANGES index c6a9e0bd2b..d62f2c0f83 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,19 @@ ======= CHANGES ======= - +0.4.8 +===== +- orm + - Added "add()" and "add_all()" to scoped_session + methods. Workaround for 0.4.7: + + from sqlalchemy.orm.scoping import ScopedSession,\ + instrument + setattr( + ScopedSession, "add", instrument("add")) + setattr( + ScopedSession, "add_all", instrument("add_all")) + 0.4.7 ===== - orm diff --git a/VERSION b/VERSION index f905682709..cb498ab2c8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.7 +0.4.8 diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py index 479b2f7374..90bc703fe8 100644 --- a/lib/sqlalchemy/orm/scoping.py +++ b/lib/sqlalchemy/orm/scoping.py @@ -97,7 +97,7 @@ def instrument(name): def do(self, *args, **kwargs): return getattr(self.registry(), name)(*args, **kwargs) return do -for meth in ('get', 'load', 'close', 'save', 'commit', 'update', 'save_or_update', 'flush', 'query', 'delete', 'merge', 'clear', 'refresh', 'expire', 'expunge', 'rollback', 'begin', 'begin_nested', 'connection', 'execute', 'scalar', 'get_bind', 'is_modified', '__contains__', '__iter__'): +for meth in ('add', 'add_all', 'get', 'load', 'close', 'save', 'commit', 'update', 'save_or_update', 'flush', 'query', 'delete', 'merge', 'clear', 'refresh', 'expire', 'expunge', 'rollback', 'begin', 'begin_nested', 'connection', 'execute', 'scalar', 'get_bind', 'is_modified', '__contains__', '__iter__'): setattr(ScopedSession, meth, instrument(meth)) def makeprop(name): diff --git a/test/orm/session.py b/test/orm/session.py index d9c11745f4..f0b19a4075 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -1042,7 +1042,22 @@ class ScopedSessionTest(ORMTest): self.assertEquals(SomeObject(id=1, data="hello", options=[SomeOtherObject(someid=1)]), Session.query(SomeObject).one()) self.assertEquals(SomeObject(id=1, data="hello", options=[SomeOtherObject(someid=1)]), SomeObject.query.one()) self.assertEquals(SomeOtherObject(someid=1), SomeOtherObject.query.filter(SomeOtherObject.someid==sso.someid).one()) - + + def test_forwards_compat_add(self): + Session = scoped_session(sessionmaker()) + class User(object): + pass + + mapper(User, table) + u1 = User() + Session.add(u1) + assert u1 in Session() + + u2, u3 = User(), User() + Session.add_all([u2, u3]) + assert u2 in Session() + assert u3 in Session() + class ScopedMapperTest(TestBase): def setUpAll(self): global metadata, table, table2