Commits

Mike Bayer committed 5da2124

- Query won't fail with weakref error when a non-mapper/class
instrumented descriptor is passed, raises
"Invalid column expession".

  • Participants
  • Parent commits 8495c19

Comments (0)

Files changed (3)

        been loaded from the database.   Helps with the creation of 
        homegrown collection loaders and such.
 
+     - Query won't fail with weakref error when a non-mapper/class
+       instrumented descriptor is passed, raises 
+       "Invalid column expession".
+       
 - sql
     - Fixed missing _label attribute on Function object, others
       when used in a select() with use_labels (such as when used

File lib/sqlalchemy/orm/util.py

         return True
     if isinstance(cls, expression.ClauseElement):
         return False
-    manager = attributes.manager_of_class(cls)
-    return manager and _INSTRUMENTOR in manager.info
-
+    if isinstance(cls, type):
+        manager = attributes.manager_of_class(cls)
+        return manager and _INSTRUMENTOR in manager.info
+    return False
+    
 def instance_str(instance):
     """Return a string describing an instance."""
 

File test/orm/mapper.py

         users.update().values({User.foobar:User.foobar + 'foo'}).execute()
         eq_(sa.select([User.foobar]).where(User.foobar=='name1foo').execute().fetchall(), [('name1foo',)])
         
+    @testing.resolve_artifact_names
+    def test_utils(self):
+        from sqlalchemy.orm.util import _is_mapped_class, _is_aliased_class
+        
+        class Foo(object):
+            x = "something"
+            @property
+            def y(self):
+                return "somethign else"
+        m = mapper(Foo, users)
+        a1 = aliased(Foo)
+        
+        f = Foo()
+
+        for fn, arg, ret in [
+            (_is_mapped_class, Foo.x, False),
+            (_is_mapped_class, Foo.y, False),
+            (_is_mapped_class, Foo, True),
+            (_is_mapped_class, f, False),
+            (_is_mapped_class, a1, True),
+            (_is_mapped_class, m, True),
+            (_is_aliased_class, a1, True),
+            (_is_aliased_class, Foo.x, False),
+            (_is_aliased_class, Foo.y, False),
+            (_is_aliased_class, Foo, False),
+            (_is_aliased_class, f, False),
+            (_is_aliased_class, a1, True),
+            (_is_aliased_class, m, False),
+        ]:
+            assert fn(arg) == ret
+
+
 
     @testing.resolve_artifact_names
     def test_prop_accessor(self):