1. paulgb
  2. sqlalchemy


Mike Bayer  committed 72006cf

- Fixed shard_id argument on ShardedSession.execute().

  • Participants
  • Parent commits 617679a
  • Branches rel_0_4

Comments (0)

Files changed (3)


View file
     - 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 

File lib/sqlalchemy/orm/session.py

View file
             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.
             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 {})

File test/orm/sharding/shard.py

View file
         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