From: Mike Bayer Date: Fri, 20 Feb 2009 15:45:25 +0000 (+0000) Subject: - Query won't fail with weakref error when a non-mapper/class X-Git-Tag: rel_0_5_3~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8b57a47cd3ffb4b7c43eb6e4eb1753d4379b1b9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Query won't fail with weakref error when a non-mapper/class instrumented descriptor is passed, raises "Invalid column expession". --- diff --git a/CHANGES b/CHANGES index 2d03e71164..c0916e3bb8 100644 --- 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 diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py index a3912d133e..37c88907b6 100644 --- a/lib/sqlalchemy/orm/util.py +++ b/lib/sqlalchemy/orm/util.py @@ -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.""" diff --git a/test/orm/mapper.py b/test/orm/mapper.py index f1f5f4a472..c1d422ec0a 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -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):