]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- same as [ticket:1019] but repaired the non-labeled use case
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 5 May 2008 16:46:24 +0000 (16:46 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 5 May 2008 16:46:24 +0000 (16:46 +0000)
      [ticket:1022]

CHANGES
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/sql/expression.py
test/orm/eager_relations.py

diff --git a/CHANGES b/CHANGES
index 4ac82c2edc5f03346f39ccdd0d965b01f979a7d7..f23004f71bd00af5d5e4175c2d90c58fd68fed36 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -48,7 +48,10 @@ CHANGES
       necessary, btw) will have the label anonymized when
       the instance is part of the eager join, to prevent
       conflicts with a subquery or column of the same name 
-      on the parent object.  [ticket:1019]
+      on the parent object.  [ticket:1019] 
+      
+    - same as [ticket:1019] but repaired the non-labeled use case
+      [ticket:1022]
 
     - Adjusted class-member inspection durint attribute and
       collection instrumentation that could be problematic when
index d7c7cebaa8df5b7393174a09fd6597c6232ca569..583a02763824944407a2119d443c0cc366757077 100644 (file)
@@ -1481,13 +1481,12 @@ class ResultProxy(object):
                 rec = props[key]
             except KeyError:
                 # fallback for targeting a ColumnElement to a textual expression
-                # it would be nice to get rid of this but we make use of it in the case where
-                # you say something like query.options(contains_alias('fooalias')) - the matching
-                # is done on strings
+                # this is a rare use case which only occurs when matching text()
+                # constructs to ColumnElements
                 if isinstance(key, expression.ColumnElement):
                     if key._label and key._label.lower() in props:
                         return props[key._label.lower()]
-                    elif key.name.lower() in props:
+                    elif hasattr(key, 'name') and key.name.lower() in props:
                         return props[key.name.lower()]
                 raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % (str(key)))
 
index 1143bf8aa44f2802768bd62fd81b976e7409011a..269d31661eb34bc0d76604e7fa77f73e1df68190 100644 (file)
@@ -2446,7 +2446,10 @@ class _ColumnElementAdapter(ColumnElement):
     key = property(key)
 
     def _label(self):
-        return self.elem._label
+        try:
+            return self.elem._label
+        except AttributeError:
+            return self.anon_label
     _label = property(_label)
 
     def _copy_internals(self, clone=_clone):
index b7ebc31a4548551ea892d8f52d1d0e6a3feb1587..b320f226a4a33f616fd1c2b56ad07d5d149f262c 100644 (file)
@@ -1045,5 +1045,11 @@ class SubqueryTest(ORMTest):
             for user in session.query(User).all():
                 self.assertEquals(user.query_score, user.prop_score)
 
+            u = session.query(User).filter_by(name='joe').one()
+            self.assertEquals(u.query_score, u.prop_score)
+            
+            for t in (tags_table, users_table):
+                t.delete().execute()
+            
 if __name__ == '__main__':
     testenv.main()