From: Mike Bayer Date: Mon, 22 Dec 2008 17:51:25 +0000 (+0000) Subject: also check for primaryjoin/secondaryjoin that equates to False, [ticket:1087] X-Git-Tag: rel_0_5_0~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bb848907339b0e69b5d5ad3d020305ce681b823;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git also check for primaryjoin/secondaryjoin that equates to False, [ticket:1087] --- diff --git a/CHANGES b/CHANGES index 323698b8e9..c5571d5c39 100644 --- a/CHANGES +++ b/CHANGES @@ -90,7 +90,7 @@ CHANGES - Extra checks added to ensure explicit primaryjoin/secondaryjoin are ClauseElement instances, to prevent more confusing errors later - on. + on. [ticket:1087] - Improved mapper() check for non-class classes. [ticket:1236] diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 5bd3c0842c..bf9bda366f 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -604,7 +604,7 @@ class RelationProperty(StrategizedProperty): # interact with Query in the same way as the original Table-bound Column objects for attr in ('primaryjoin', 'secondaryjoin'): val = getattr(self, attr) - if val: + if val is not None: util.assert_arg_type(val, sql.ClauseElement, attr) setattr(self, attr, _orm_deannotate(val)) diff --git a/test/orm/relationships.py b/test/orm/relationships.py index 181ed375ce..f022f433b9 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -666,7 +666,21 @@ class JoinConditionErrorTest(testing.TestBase): c2 = relation(C1, primaryjoin=C1.id) self.assertRaises(sa.exc.ArgumentError, compile_mappers) - + + def test_clauseelement_pj_false(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="x"=="y") + + self.assertRaises(sa.exc.ArgumentError, compile_mappers) + def test_fk_error_raised(self): m = MetaData()