From fdc92f0226779d608a5082e2f9009a332c142eb1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 12 Feb 2012 17:28:20 -0500 Subject: [PATCH] - [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] --- CHANGES | 6 ++++++ lib/sqlalchemy/orm/mapper.py | 19 +++++++++++++------ test/orm/test_mapper.py | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index a97a9c60db..be816002d6 100644 --- 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 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 42acb4928c..e96b7549a9 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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 diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index e2ae823220..1c5f29b716 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -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 -- 2.47.2