1. diana clarke
  2. sqlalchemy-2450

Commits

Mike Bayer  committed 91f78a8

- [ticket:768] dont assume join criterion consists only of column objects

  • Participants
  • Parent commits 5301c57
  • Branches rel_0_3

Comments (0)

Files changed (3)

File CHANGES

View file
     - tweak DISTINCT precedence for clauses like
       `func.count(t.c.col.distinct())`
     - Fixed detection of internal '$' characters in :bind$params [ticket:719]
+    - [ticket:768] dont assume join criterion consists only of column objects
+    
 - orm
     - added a check for joining from A->B using join(), along two
       different m2m tables.  this raises an error in 0.3 but is 

File lib/sqlalchemy/sql.py

View file
     encodedname = property(lambda s: s.name.encode('ascii', 'backslashreplace'))
 
     def _init_primary_key(self):
+        from sqlalchemy import schema
         pkcol = util.Set([c for c in self._adjusted_exportable_columns() if c.primary_key])
     
         equivs = {}
                     
         class BinaryVisitor(ClauseVisitor):
             def visit_binary(self, binary):
-                if binary.operator == '=':
+                if binary.operator == '=' and isinstance(binary.left, schema.Column) and isinstance(binary.right, schema.Column):
                     add_equiv(binary.left, binary.right)
         BinaryVisitor().traverse(self.onclause)
         

File test/sql/selectable.py

View file
         j.foreign_keys
         assert list(j.primary_key) == [a.c.id]
 
+    def test_non_column_clause(self):
+        meta = MetaData()
+        a = Table('a', meta, Column('id', Integer, primary_key=True), Column('x', Integer))
+        b = Table('b', meta, Column('id', Integer, ForeignKey('a.id'), primary_key=True), Column('x', Integer, primary_key=True))
+
+        j = a.join(b, and_(a.c.id==b.c.id, b.c.x==5))
+        assert str(j) == "a JOIN b ON a.id = b.id AND b.x = :b_x", str(j)
+        assert list(j.primary_key) == [a.c.id, b.c.x]
+
         
         
 if __name__ == "__main__":