]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Query won't fail with weakref error when a non-mapper/class
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Feb 2009 15:45:25 +0000 (15:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Feb 2009 15:45:25 +0000 (15:45 +0000)
instrumented descriptor is passed, raises
"Invalid column expession".

CHANGES
lib/sqlalchemy/orm/util.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 2d03e71164f8f71adb5fd3f6f40db3cfee6c6348..c0916e3bb87c8aa421bc6e278c3351441212747c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -58,6 +58,10 @@ CHANGES
        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
index a3912d133e729d6385878a8cae322a11a5caf85a..37c88907b6f2dde2895901973180af29bae6bfbf 100644 (file)
@@ -593,9 +593,11 @@ def _is_mapped_class(cls):
         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."""
 
index f1f5f4a472112db743e238a232a7bf5a363535f0..c1d422ec0ab351c6e6182ff8344dc533476897a1 100644 (file)
@@ -38,6 +38,38 @@ class MapperTest(_fixtures.FixtureTest):
         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):