From: Mike Bayer Date: Sun, 25 Oct 2009 01:40:17 +0000 (+0000) Subject: - Fixed a slight inaccuracy in the sharding example. X-Git-Tag: rel_0_5_7~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=766578f13a27ac9e2081b898319380f886e267c1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed a slight inaccuracy in the sharding example. Comparing equivalence of columns in the ORM is best accomplished using col1.shares_lineage(col2). [ticket:1491] --- diff --git a/CHANGES b/CHANGES index 09214ce19c..55ffae23ac 100644 --- a/CHANGES +++ b/CHANGES @@ -63,6 +63,11 @@ CHANGES the column will be propagated down to subclasses. [ticket:1570] This is the reverse situation as that of [ticket:1523], fixed in 0.5.6. + + - Fixed a slight inaccuracy in the sharding example. + Comparing equivalence of columns in the ORM is best + accomplished using col1.shares_lineage(col2). + [ticket:1491] 0.5.6 ===== diff --git a/examples/sharding/attribute_shard.py b/examples/sharding/attribute_shard.py index 2f03a5a344..2ac0c88ff8 100644 --- a/examples/sharding/attribute_shard.py +++ b/examples/sharding/attribute_shard.py @@ -134,7 +134,13 @@ def query_chooser(query): # and convert to shard ids class FindContinent(sql.ClauseVisitor): def visit_binary(self, binary): - if binary.left is weather_locations.c.continent: + # "shares_lineage()" returns True if both columns refer to the same + # statement column, adjusting for any annotations present. + # (an annotation is an internal clone of a Column object + # and occur when using ORM-mapped attributes like + # "WeatherLocation.continent"). A simpler comparison, though less accurate, + # would be "binary.left.key == 'continent'". + if binary.left.shares_lineage(weather_locations.c.continent): if binary.operator == operators.eq: ids.append(shard_lookup[binary.right.value]) elif binary.operator == operators.in_op: diff --git a/test/orm/sharding/test_shard.py b/test/orm/sharding/test_shard.py index 89e23fb759..300e4ccf7e 100644 --- a/test/orm/sharding/test_shard.py +++ b/test/orm/sharding/test_shard.py @@ -83,7 +83,7 @@ class ShardTest(TestBase): class FindContinent(sql.ClauseVisitor): def visit_binary(self, binary): - if binary.left is weather_locations.c.continent: + if binary.left.shares_lineage(weather_locations.c.continent): if binary.operator == operators.eq: ids.append(shard_lookup[binary.right.value]) elif binary.operator == operators.in_op: