From: Mike Bayer Date: Wed, 25 Nov 2009 17:34:25 +0000 (+0000) Subject: - relation primaryjoin and secondaryjoin now check that they X-Git-Tag: rel_0_6beta1~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fedc5e0708c27b646d32f88f532b34f0f898997;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - relation primaryjoin and secondaryjoin now check that they are column-expressions, not just clause elements. this prohibits things like FROM expressions being placed there directly. [ticket:1622] --- diff --git a/CHANGES b/CHANGES index 0f19a1f0e4..2c2995f09d 100644 --- a/CHANGES +++ b/CHANGES @@ -99,6 +99,11 @@ CHANGES may break queries with literal expressions that do not have labels applied (i.e. literal('foo'), etc.) [ticket:1568] + + - relation primaryjoin and secondaryjoin now check that they + are column-expressions, not just clause elements. this prohibits + things like FROM expressions being placed there directly. + [ticket:1622] - the "dont_load=True" flag on Session.merge() is deprecated and is now "load=False". diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 1fd7d48a99..190be8d660 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -743,7 +743,7 @@ class RelationProperty(StrategizedProperty): for attr in ('primaryjoin', 'secondaryjoin'): val = getattr(self, attr) if val is not None: - util.assert_arg_type(val, sql.ClauseElement, attr) + util.assert_arg_type(val, sql.ColumnElement, attr) setattr(self, attr, _orm_deannotate(val)) if self.order_by is not False and self.order_by is not None: diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index aa1565794f..63d66b7428 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -886,7 +886,24 @@ class JoinConditionErrorTest(testing.TestBase): c2 = relation(C1, primaryjoin="x"=="y") assert_raises(sa.exc.ArgumentError, compile_mappers) - + + def test_only_column_elements(self): + m = MetaData() + t1 = Table('t1', m, + Column('id', Integer, primary_key=True), + Column('foo_id', Integer, ForeignKey('t2.id')), + ) + t2 = Table('t2', m, + Column('id', Integer, primary_key=True), + ) + class C1(object): + pass + class C2(object): + pass + + mapper(C1, t1, properties={'c2':relation(C2, primaryjoin=t1.join(t2))}) + mapper(C2, t2) + assert_raises(sa.exc.ArgumentError, compile_mappers) def test_fk_error_raised(self): m = MetaData()