From e7dd4efb3e26d600c38d6e7467a01b72881a8a0d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 22 Nov 2008 20:37:16 +0000 Subject: [PATCH] - Extra checks added to ensure explicit primaryjoin/secondaryjoin are ClauseElement instances, to prevent more confusing errors later on. --- CHANGES | 7 ++++++- lib/sqlalchemy/orm/properties.py | 1 + test/orm/relationships.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index b3a05ebe9d..774799e83f 100644 --- 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]. diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index dbc3430a06..bd493aaf25 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -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: diff --git a/test/orm/relationships.py b/test/orm/relationships.py index 00bc35a7f7..22665f9906 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -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, -- 2.47.3