From: Mike Bayer Date: Sun, 28 Dec 2008 20:06:50 +0000 (+0000) Subject: - Fixed shard_id argument on ShardedSession.execute(). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=982787d822251f7f7b710099cfed684a4f944570;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed shard_id argument on ShardedSession.execute(). [ticket:1072] --- diff --git a/CHANGES b/CHANGES index 88e316ae7e..2440cf575b 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,9 @@ CHANGES - Class-bound accessor can be used as the argument to relation() order_by. [ticket:939] + + - Fixed shard_id argument on ShardedSession.execute(). + [ticket:1072] - sql - Connection.invalidate() checks for closed status diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 9efe52d847..d1c648616a 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -601,7 +601,7 @@ class Session(object): else: return engine.contextual_connect(**kwargs) - def execute(self, clause, params=None, mapper=None, instance=None): + def execute(self, clause, params=None, mapper=None, instance=None, **kw): """Execute the given clause, using the current transaction (if any). Returns a ``ResultProxy`` corresponding to the execution's results. @@ -621,9 +621,14 @@ class Session(object): instance used by some Query operations to further identify the proper bind, in the case of ShardedSession. + + \**kw + Additional keyword arguments are sent to ``get_bind()`` + which locates a connectable to use for the execution. + Subclasses of ``Session`` may override this. """ - engine = self.get_bind(mapper, clause=clause, instance=instance) + engine = self.get_bind(mapper, clause=clause, instance=instance, **kw) return self.__connection(engine, close_with_result=True).execute(clause, params or {}) diff --git a/test/orm/sharding/shard.py b/test/orm/sharding/shard.py index d231b14a2c..5841794746 100644 --- a/test/orm/sharding/shard.py +++ b/test/orm/sharding/shard.py @@ -144,6 +144,7 @@ class ShardTest(TestBase): assert db2.execute(weather_locations.select()).fetchall() == [(1, 'Asia', 'Tokyo')] assert db1.execute(weather_locations.select()).fetchall() == [(2, 'North America', 'New York'), (3, 'North America', 'Toronto')] + assert sess.execute(weather_locations.select(), shard_id='asia').fetchall() == [(1, 'Asia', 'Tokyo')] t = sess.query(WeatherLocation).get(tokyo.id) assert t.city == tokyo.city