]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug whereby if a method name
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Feb 2012 22:28:20 +0000 (17:28 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Feb 2012 22:28:20 +0000 (17:28 -0500)
conflicted with a column name, a
TypeError would be raised when the mapper
tried to inspect the __get__() method
on the method object.  [ticket:2352]

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

diff --git a/CHANGES b/CHANGES
index a97a9c60db80d7d871ef2ec177e48a4ea64e56c1..be816002d68ba8d5db9ba88fb61d073d38a6fb63 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,12 @@ CHANGES
     happen if there's really an UPDATE to occur.
     [ticket:2390]
 
+  - [bug] Fixed bug whereby if a method name
+    conflicted with a column name, a
+    TypeError would be raised when the mapper
+    tried to inspect the __get__() method
+    on the method object.  [ticket:2352]
+
 - sql
   - [bug] Added support for using the .key
     of a Column as a string identifier in a 
index 42acb4928c7656c4cb278f1f0b047f360e22e749..e96b7549a9da892f99d658133f3bd1c3b87e3a66 100644 (file)
@@ -1452,12 +1452,19 @@ class Mapper(object):
         return result
 
     def _is_userland_descriptor(self, obj):
-        return not isinstance(obj, 
-                    (MapperProperty, attributes.QueryableAttribute)) and \
-                    hasattr(obj, '__get__') and not \
-                     isinstance(obj.__get__(None, obj),
-                                    attributes.QueryableAttribute)
-
+        if isinstance(obj, (MapperProperty, 
+                            attributes.QueryableAttribute)):
+            return False
+        elif not hasattr(obj, '__get__'):
+            return False
+        else:
+            obj = util.unbound_method_to_callable(obj)
+            if isinstance(
+                        obj.__get__(None, obj),
+                        attributes.QueryableAttribute
+                    ):
+                return False
+        return True
 
     def _should_exclude(self, name, assigned_name, local, column):
         """determine whether a particular property should be implicitly
index e2ae8232201021a4d49aff17bb28d11fba7e1f57..1c5f29b71677bac3aeaf6f6bf521e1d57020024e 100644 (file)
@@ -327,6 +327,14 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
         mapper(Foo, addresses, inherits=User)
         assert getattr(Foo().__class__, 'name').impl is not None
 
+    def test_check_descriptor_as_method(self):
+        User, users = self.classes.User, self.tables.users
+
+        m = mapper(User, users)
+        class MyClass(User):
+            def foo(self):
+                pass
+        m._is_userland_descriptor(MyClass.foo)
 
     def test_configure_on_get_props_1(self):
         User, users = self.classes.User, self.tables.users