diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-10 13:50:06 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-10 13:50:06 -0400 |
commit | 58c8c4ce77d1e0e9f3a25f4e4dbdd0013cb9044b (patch) | |
tree | 0218e0c116d1886441cebf0766d56ecb4be34061 | |
parent | b614a24c5ddf4c7c7aa45e1eaeb3f82e36737729 (diff) | |
download | sqlalchemy-58c8c4ce77d1e0e9f3a25f4e4dbdd0013cb9044b.tar.gz |
Fixed bug where sending a composite attribute into :meth:`.Query.order_by`
would produce a parenthesized expression not accepted by some databases.
[ticket:2754]
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 7 | ||||
-rw-r--r-- | doc/build/changelog/changelog_09.rst | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/descriptor_props.py | 2 | ||||
-rw-r--r-- | test/orm/test_composites.py | 28 |
4 files changed, 42 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index bedb5da02..ffd5bd4e4 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -8,6 +8,13 @@ .. change:: :tags: bug, orm + :tickets: 2754 + + Fixed bug where sending a composite attribute into :meth:`.Query.order_by` + would produce a parenthesized expression not accepted by some databases. + + .. change:: + :tags: bug, orm :tickets: 2755 Fixed the interaction between composite attributes and diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 1f14b33ff..b7d25c07a 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -6,6 +6,13 @@ .. changelog:: :version: 0.9.0 + .. change:: + :tags: bug, orm + :tickets: 2754 + + Fixed bug where sending a composite attribute into :meth:`.Query.order_by` + would produce a parenthesized expression not accepted by some databases. + Also in 0.8.2. .. change:: :tags: bug, orm diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index c565cb715..97ca6d2eb 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -320,7 +320,7 @@ class CompositeProperty(DescriptorProperty): """ def __clause_element__(self): - return expression.ClauseList(*self._comparable_elements) + return expression.ClauseList(group=False, *self._comparable_elements) __hash__ = None diff --git a/test/orm/test_composites.py b/test/orm/test_composites.py index 379abfa13..5e7b91f3e 100644 --- a/test/orm/test_composites.py +++ b/test/orm/test_composites.py @@ -712,7 +712,9 @@ class ConfigurationTest(fixtures.MappedTest): }) self._test_roundtrip() -class ComparatorTest(fixtures.MappedTest): +class ComparatorTest(fixtures.MappedTest, testing.AssertsCompiledSQL): + __dialect__ = 'default' + @classmethod def define_tables(cls, metadata): Table('edge', metadata, @@ -836,4 +838,28 @@ class ComparatorTest(fixtures.MappedTest): assert edge_1 in near_edges and edge_2 in near_edges + def test_order_by(self): + self._fixture(False) + Edge = self.classes.Edge + s = Session() + self.assert_compile( + s.query(Edge).order_by(Edge.start, Edge.end), + "SELECT edge.id AS edge_id, edge.x1 AS edge_x1, " + "edge.y1 AS edge_y1, edge.x2 AS edge_x2, edge.y2 AS edge_y2 " + "FROM edge ORDER BY edge.x1, edge.y1, edge.x2, edge.y2" + ) + + def test_order_by_aliased(self): + self._fixture(False) + Edge = self.classes.Edge + s = Session() + ea = aliased(Edge) + self.assert_compile( + s.query(ea).order_by(ea.start, ea.end), + "SELECT edge_1.id AS edge_1_id, edge_1.x1 AS edge_1_x1, " + "edge_1.y1 AS edge_1_y1, edge_1.x2 AS edge_1_x2, " + "edge_1.y2 AS edge_1_y2 " + "FROM edge AS edge_1 ORDER BY edge_1.x1, edge_1.y1, " + "edge_1.x2, edge_1.y2" + ) |