]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed a slight inaccuracy in the sharding example.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 Oct 2009 01:40:23 +0000 (01:40 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 Oct 2009 01:40:23 +0000 (01:40 +0000)
Comparing equivalence of columns in the ORM is best
accomplished using col1.shares_lineage(col2).
[ticket:1491]

CHANGES
examples/sharding/attribute_shard.py
test/orm/sharding/test_shard.py

diff --git a/CHANGES b/CHANGES
index 5697efc99370b7cf242ddf175ea5fa45ac8ee037..5a3ba9c45c28c7a785342d0048603a959c46a8cd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -658,6 +658,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
 =====
index 2f03a5a34488874d3307102b9f010be594df241e..2ac0c88ff8cb8ae8797a5080111bf2f91b9867fa 100644 (file)
@@ -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:
index e8ffaa7cad599b2a3d5a6d53981a10f8d7e0f8f9..06a38848bdbf727fbc40acc5b4211cb2be5163f2 100644 (file)
@@ -87,7 +87,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: