diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-11-04 13:27:59 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-11-04 13:27:59 +0000 |
| commit | 43348d6163959217c6b6d4d0818e3a261a359285 (patch) | |
| tree | 9e28af4d32e51409d38b36810f92ace2e59a6e62 | |
| parent | d79d48ca55a3576723cd3bdde05b426de07c1e69 (diff) | |
| download | sqlalchemy-43348d6163959217c6b6d4d0818e3a261a359285.tar.gz | |
- Fixed bug where Query would crash if a join() with no clear
"left" side were called when a non-mapped column entity
appeared in the columns list. [ticket:1602]
| -rw-r--r-- | CHANGES | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 7 | ||||
| -rw-r--r-- | test/orm/test_query.py | 16 |
3 files changed, 22 insertions, 5 deletions
@@ -675,6 +675,10 @@ CHANGES - Fixed the call to get_committed_value() on CompositeProperty. [ticket:1504] + + - Fixed bug where Query would crash if a join() with no clear + "left" side were called when a non-mapped column entity + appeared in the columns list. [ticket:1602] - sql - Fixed the "numeric" paramstyle, which apparently is the diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 0463c548a..03da99568 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2129,10 +2129,13 @@ class _ColumnEntity(_QueryEntity): self.froms.add(from_obj) def corresponds_to(self, entity): - if _is_aliased_class(entity): + if self.entity_zero is None: + return False + elif _is_aliased_class(entity): return entity is self.entity_zero else: - return not _is_aliased_class(self.entity_zero) and entity.base_mapper.common_parent(self.entity_zero) + return not _is_aliased_class(self.entity_zero) and \ + entity.base_mapper.common_parent(self.entity_zero) def _resolve_expr_against_query_aliases(self, query, expr, context): return query._adapt_clause(expr, False, True) diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 79dd2a58a..98e85fa41 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -1375,9 +1375,6 @@ class InheritedJoinTest(_base.MappedTest, AssertsCompiledSQL): class JoinTest(QueryTest, AssertsCompiledSQL): - def test_foo(self): - sess = create_session() - def test_single_name(self): sess = create_session() @@ -1553,6 +1550,19 @@ class JoinTest(QueryTest, AssertsCompiledSQL): [] ) + def test_join_nonmapped_column(self): + """test that the search for a 'left' doesn't trip on non-mapped cols""" + sess = create_session() + + # intentionally join() with a non-existent "left" side + self.assert_compile( + sess.query(User.id, literal_column('foo')).join(Order.user), + "SELECT users.id AS users_id, foo FROM orders JOIN users ON users.id = orders.user_id" + , use_default_dialect=True + ) + + + def test_backwards_join(self): # a more controversial feature. join from # User->Address, but the onclause is Address.user. |
