]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Extra checks added to ensure explicit
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Nov 2008 20:37:16 +0000 (20:37 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Nov 2008 20:37:16 +0000 (20:37 +0000)
primaryjoin/secondaryjoin are ClauseElement
instances, to prevent more confusing errors later
on.

CHANGES
lib/sqlalchemy/orm/properties.py
test/orm/relationships.py

diff --git a/CHANGES b/CHANGES
index b3a05ebe9d00328e63336e5f897918318142e470..774799e83f5e0b661e0d2a5443538f280b64609d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -17,7 +17,12 @@ CHANGES
 
     - Comparison of many-to-one relation to NULL is
       properly converted to IS NOT NULL based on not_().
-      
+     
+    - Extra checks added to ensure explicit 
+      primaryjoin/secondaryjoin are ClauseElement 
+      instances, to prevent more confusing errors later 
+      on.
+       
 - sql
     - Fixed the import weirdness in sqlalchemy.sql
       to not export __names__ [ticket:1215].
index dbc3430a06d570be1d90476ce3471998ae0910e6..bd493aaf25219334feec8b845d4f4a31b62de7ae 100644 (file)
@@ -601,6 +601,7 @@ class PropertyLoader(StrategizedProperty):
         for attr in ('primaryjoin', 'secondaryjoin'):
             val = getattr(self, attr)
             if val:
+                util.assert_arg_type(val, sql.ClauseElement, attr)
                 setattr(self, attr, _orm_deannotate(val))
         
         if self.order_by:
index 00bc35a7f78bd56ff9dadc2763c9240a7b2c0586..22665f99064dd5c12455b9235a813566d43e4b54 100644 (file)
@@ -652,6 +652,22 @@ class RelationTest6(_base.MappedTest):
 
 
 class JoinConditionErrorTest(testing.TestBase):
+    
+    def test_clauseelement_pj(self):
+        from sqlalchemy.ext.declarative import declarative_base
+        Base = declarative_base()
+        class C1(Base):
+            __tablename__ = 'c1'
+            id = Column('id', Integer, primary_key=True)
+        class C2(Base):
+            __tablename__ = 'c2'
+            id = Column('id', Integer, primary_key=True)
+            c1id = Column('c1id', Integer, ForeignKey('c1.id'))
+            c2 = relation(C1, primaryjoin=C1.id)
+        
+        self.assertRaises(sa.exc.ArgumentError, compile_mappers)
+            
+    
     def test_fk_error_raised(self):
         m = MetaData()
         t1 = Table('t1', m,