summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/changelog_10.rst13
-rw-r--r--lib/sqlalchemy/__init__.py2
-rw-r--r--lib/sqlalchemy/sql/selectable.py3
-rw-r--r--test/sql/test_text.py14
4 files changed, 30 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index eb68b43a4..9f68d05eb 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -16,6 +16,19 @@
:start-line: 5
.. changelog::
+ :version: 1.0.0b4
+
+ .. change::
+ :tags: bug, sql
+ :tickets: 3335
+
+ Fixed bug in new "label resolution" feature of :ticket:`2992` where
+ the string label placed in the order_by() or group_by() of a statement
+ would place higher priority on the name as found
+ inside the FROM clause instead of a more locally available name
+ inside the columns clause.
+
+.. changelog::
:version: 1.0.0b3
:released: March 20, 2015
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py
index 94ab772b1..c1e84733c 100644
--- a/lib/sqlalchemy/__init__.py
+++ b/lib/sqlalchemy/__init__.py
@@ -120,7 +120,7 @@ from .schema import (
from .inspection import inspect
from .engine import create_engine, engine_from_config
-__version__ = '1.0.0b3'
+__version__ = '1.0.0b4'
def __go(lcls):
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index 6520f08fc..b5a7489bf 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -2680,7 +2680,8 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect):
only_froms = dict(
(c.key, c) for c in
_select_iterables(self.froms) if c._allow_label_resolve)
- with_cols.update(only_froms)
+ for key, value in only_froms.items():
+ with_cols.setdefault(key, value)
return with_cols, only_froms
diff --git a/test/sql/test_text.py b/test/sql/test_text.py
index c2f4d2c15..4483597ac 100644
--- a/test/sql/test_text.py
+++ b/test/sql/test_text.py
@@ -574,6 +574,20 @@ class OrderByLabelResolutionTest(fixtures.TestBase, AssertsCompiledSQL):
"FROM mytable AS mytable_1 ORDER BY mytable_1.name"
)
+ def test_order_by_outermost_label(self):
+ # test [ticket:3335], assure that order_by("foo")
+ # catches the label named "foo" in the columns clause only,
+ # and not the label named "foo" in the FROM clause
+ s1 = select([table1.c.myid.label("foo"), table1.c.name]).alias()
+ stmt = select([s1.c.name, func.bar().label("foo")]).order_by("foo")
+
+ self.assert_compile(
+ stmt,
+ "SELECT anon_1.name, bar() AS foo FROM "
+ "(SELECT mytable.myid AS foo, mytable.name AS name "
+ "FROM mytable) AS anon_1 ORDER BY foo"
+ )
+
def test_unresolvable_warning_order_by(self):
stmt = select([table1.c.myid]).order_by('foobar')
self._test_warning(