diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-09-08 19:51:35 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-09-08 19:51:35 +0000 |
| commit | fc753a06475c2fa571d09d73d3169b66c272c8d6 (patch) | |
| tree | 718820e31a95eadc332277eed905d21ba09a6edf /lib/sqlalchemy/orm/shard.py | |
| parent | bf35590e15de3fac7977757d89bc994400f26125 (diff) | |
| download | sqlalchemy-fc753a06475c2fa571d09d73d3169b66c272c8d6.tar.gz | |
- fixes to ShardedSession to work with deferred columns [ticket:771].
- user-defined shard_chooser() function must accept "clause=None"
argument; this is the ClauseElement passed to session.execute(statement)
and can be used to determine correct shard id (since execute() doesn't
take an instance)
Diffstat (limited to 'lib/sqlalchemy/orm/shard.py')
| -rw-r--r-- | lib/sqlalchemy/orm/shard.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/sqlalchemy/orm/shard.py b/lib/sqlalchemy/orm/shard.py index 752806c0c..48e057966 100644 --- a/lib/sqlalchemy/orm/shard.py +++ b/lib/sqlalchemy/orm/shard.py @@ -9,11 +9,11 @@ class ShardedSession(Session): """construct a ShardedSession. shard_chooser - a callable which, passed a Mapper and a mapped instance, returns a - shard ID. this id may be based off of the attributes present within the - object, or on some round-robin scheme. If the scheme is based on a - selection, it should set whatever state on the instance to mark it in - the future as participating in that shard. + a callable which, passed a Mapper, a mapped instance, and possibly a + SQL clause, returns a shard ID. this id may be based off of the + attributes present within the object, or on some round-robin scheme. If + the scheme is based on a selection, it should set whatever state on the + instance to mark it in the future as participating in that shard. id_chooser a callable, passed a query and a tuple of identity values, @@ -47,9 +47,9 @@ class ShardedSession(Session): else: return self.get_bind(mapper, shard_id=shard_id, instance=instance).contextual_connect(**kwargs) - def get_bind(self, mapper, shard_id=None, instance=None): + def get_bind(self, mapper, shard_id=None, instance=None, clause=None): if shard_id is None: - shard_id = self.shard_chooser(mapper, instance) + shard_id = self.shard_chooser(mapper, instance, clause=clause) return self.__binds[shard_id] def bind_shard(self, shard_id, bind): |
