diff options
| -rw-r--r-- | CHANGES | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/util.py | 8 | ||||
| -rw-r--r-- | test/orm/mapper.py | 32 |
3 files changed, 41 insertions, 3 deletions
@@ -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 a3912d133..37c88907b 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 f1f5f4a47..c1d422ec0 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): |
