From 8804e1963f7f391bfc29feca7155e3a5f9bb097d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 17 Jul 2009 15:10:54 +0000 Subject: [PATCH] - Fixed a bug in extract() introduced in 0.5.4 whereby the string "field" argument was getting treated as a ClauseElement, causing various errors within more complex SQL transformations. --- CHANGES | 9 ++++++++- lib/sqlalchemy/sql/expression.py | 3 +-- test/sql/test_generative.py | 12 +++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 2ea185a91a..f6d89c29d9 100644 --- a/CHANGES +++ b/CHANGES @@ -3,7 +3,14 @@ ======= CHANGES ======= - +0.5.6 +===== +- sql + - Fixed a bug in extract() introduced in 0.5.4 whereby + the string "field" argument was getting treated as a + ClauseElement, causing various errors within more + complex SQL transformations. + 0.5.5 ======= - general diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 565c3407b7..b5eb0eee97 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2326,11 +2326,10 @@ class _Extract(ColumnElement): self.expr = _literal_as_binds(expr, None) def _copy_internals(self, clone=_clone): - self.field = clone(self.field) self.expr = clone(self.expr) def get_children(self, **kwargs): - return self.field, self.expr + return self.expr, @property def _from_objects(self): diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py index ca427ca5f5..7c094c26b0 100644 --- a/test/sql/test_generative.py +++ b/test/sql/test_generative.py @@ -310,7 +310,17 @@ class ClauseTest(TestBase, AssertsCompiledSQL): "table1.col3 AS col3 FROM table1 WHERE table1.col1 = :col1_1) AS anon_1, "\ "(SELECT table1.col1 AS col1, table1.col2 AS col2, table1.col3 AS col3 FROM table1 WHERE table1.col1 = :col1_2) AS anon_2 "\ "WHERE anon_1.col2 = anon_2.col2") - + + def test_extract(self): + s = select([extract('foo', t1.c.col1).label('col1')]) + self.assert_compile(s, "SELECT EXTRACT(foo FROM table1.col1) AS col1 FROM table1") + + s2 = CloningVisitor().traverse(s).alias() + s3 = select([s2.c.col1]) + self.assert_compile(s, "SELECT EXTRACT(foo FROM table1.col1) AS col1 FROM table1") + self.assert_compile(s3, "SELECT anon_1.col1 FROM (SELECT EXTRACT(foo FROM table1.col1) AS col1 FROM table1) AS anon_1") + + @testing.emits_warning('.*replaced by another column with the same key') def test_alias(self): subq = t2.select().alias('subq') -- 2.47.3