]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed exception throw which would occur when string-based
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Sep 2008 21:26:49 +0000 (21:26 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Sep 2008 21:26:49 +0000 (21:26 +0000)
primaryjoin condition was used in conjunction with backref.

CHANGES
lib/sqlalchemy/ext/declarative.py
test/ext/declarative.py

diff --git a/CHANGES b/CHANGES
index b395f6edd750f3c95a52820f1bac80f5e33ec485..7697e4c009155746999369019e990c8ee2d3c329 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -107,7 +107,7 @@ CHANGES
       by the ORM.
 
     - Session.delete() adds the given object to the session if 
-      not already present.  This was a regression bug from 0.4
+      not already present.  This was a regression bug from 0.4.
       [ticket:1150]
       
     - The `echo_uow` flag on `Session` is deprecated, and unit-of-work
@@ -116,7 +116,10 @@ CHANGES
 - declarative
     - Fixed bug whereby mapper couldn't initialize if a composite
       primary key referenced another table that was not defined
-      yet [ticket:1161]
+      yet. [ticket:1161]
+    
+    - Fixed exception throw which would occur when string-based
+      primaryjoin condition was used in conjunction with backref.
       
 - schema
     - Added "sorted_tables" accessor to MetaData, which returns
index 65af2da7ac9a9da22430fb11221287e7c66dcd44..85ccea64887b5116ff9b843931f4ab8abd588c27 100644 (file)
@@ -374,6 +374,12 @@ def _deferred_relation(cls, prop):
             if isinstance(v, basestring):
                 setattr(prop, attr, resolve_arg(v))
 
+        if prop.backref:
+            for attr in ('primaryjoin', 'secondaryjoin'):
+               if attr in prop.backref.kwargs and isinstance(prop.backref.kwargs[attr], basestring):
+                   prop.backref.kwargs[attr] = resolve_arg(prop.backref.kwargs[attr])
+
+
     return prop
 
 def synonym_for(name, map_column=False):
index 3121f959fe77b63052ed7ba240d065422450a9ef..772dca8e13947c57b991dda27ada4fa87adb84a6 100644 (file)
@@ -4,7 +4,7 @@ from sqlalchemy.ext import declarative as decl
 from sqlalchemy import exc
 from testlib import sa, testing
 from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, ForeignKeyConstraint, asc
-from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers
+from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref
 from testlib.testing import eq_
 from orm._base import ComparableEntity
 
@@ -114,7 +114,27 @@ class DeclarativeTest(testing.TestBase, testing.AssertsExecutionResults):
             id = Column(Integer, primary_key=True)
             rel = relation("User", primaryjoin="User.addresses==Foo.id")
         self.assertRaisesMessage(exc.InvalidRequestError, "'addresses' is not an instance of ColumnProperty", compile_mappers)
-    
+
+    def test_string_dependency_resolution_in_backref(self):
+        class User(Base, ComparableEntity):
+            __tablename__ = 'users'
+            id = Column(Integer, primary_key=True)
+            name = Column(String(50))
+            addresses = relation("Address", 
+                primaryjoin="User.id==Address.user_id", 
+                backref="user"
+                )
+
+        class Address(Base, ComparableEntity):
+            __tablename__ = 'addresses'
+            id = Column(Integer, primary_key=True)
+            email = Column(String(50))
+            user_id = Column(Integer, ForeignKey('users.id'))  
+
+        compile_mappers()
+        eq_(str(User.addresses.property.primaryjoin), str(Address.user.property.primaryjoin))
+        
+        
     def test_uncompiled_attributes_in_relation(self):
         class Address(Base, ComparableEntity):
             __tablename__ = 'addresses'