From 9dba65b381a53d0126cf4b0a153be506387f1b5c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 10 Jun 2013 13:50:06 -0400 Subject: [PATCH] Fixed bug where sending a composite attribute into :meth:`.Query.order_by` would produce a parenthesized expression not accepted by some databases. [ticket:2754] Conflicts: doc/build/changelog/changelog_09.rst --- doc/build/changelog/changelog_08.rst | 7 +++++++ lib/sqlalchemy/orm/descriptor_props.py | 2 +- test/orm/test_composites.py | 28 +++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index bedb5da024..ffd5bd4e4d 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,13 @@ .. changelog:: :version: 0.8.2 + .. 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 diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index dc2d770d74..e4c0d1525a 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 ed80d6105e..9b582ce17a 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" + ) -- 2.47.2