Commits

Mike Bayer  committed 81142ab

fixed endless loop bug in select_by(), if the traversal hit
two mappers that referenced each other

  • Participants
  • Parent commits 1b7c9c2

Comments (0)

Files changed (3)

+0.2.5
+- fixed endless loop bug in select_by(), if the traversal hit
+two mappers that referenced each other
+
 0.2.4
 - try/except when the mapper sets init.__name__ on a mapped class,
 supports python 2.3

File lib/sqlalchemy/orm/query.py

     def _locate_prop(self, key):
         import properties
         keys = []
+        seen = util.Set()
         def search_for_prop(mapper):
+            if mapper in seen:
+                return None
+            seen.add(mapper)
             if mapper.props.has_key(key):
                 prop = mapper.props[key]
                 if isinstance(prop, properties.PropertyLoader):

File test/orm/mapper.py

         l = create_session().query(User).select(users.c.user_name.endswith('ed'))
         self.assert_result(l, User, *user_result[1:3])
 
+    def testrecursiveselectby(self):
+        """test that no endless loop occurs when traversing for select_by"""
+        m = mapper(User, users, properties={
+            'orders':relation(mapper(Order, orders), backref='user'),
+            'addresses':relation(mapper(Address, addresses), backref='user'),
+        })
+        q = create_session().query(m)
+        q.select_by(email_address='foo')
+        
     def testjoinvia(self):
         m = mapper(User, users, properties={
             'orders':relation(mapper(Order, orders, properties={