From: Mike Bayer Date: Sun, 19 Jul 2015 21:56:18 +0000 (-0400) Subject: - changelog for #3459, fixes #3459 X-Git-Tag: rel_1_0_7~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c7312cc508eadc9e85a3de0dc56c9906dccdf7a1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - changelog for #3459, fixes #3459 - test for .cast() method has no good place now except for test_cast in test_compiler.py --- diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst index a2b4273bf6..1be278a9af 100644 --- a/doc/build/changelog/changelog_10.rst +++ b/doc/build/changelog/changelog_10.rst @@ -18,6 +18,15 @@ .. changelog:: :version: 1.0.7 + .. change:: + :tags: feature, sql + :tickets: 3459 + :pullreq: bitbucket:56 + + Added a :meth:`.ColumnElement.cast` method which performs the same + purpose as the standalone :func:`.cast` function. Pull request + courtesy Sebastian Bank. + .. change:: :tags: bug, engine :tickets: 3481 diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 4af1e44634..a44c308eb7 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -847,7 +847,10 @@ class ColumnElement(operators.ColumnOperators, ClauseElement): def cast(self, type_): """Produce a type cast, i.e. ``CAST( AS )``. - This is a shortcut to the :func:`.cast` function. + This is a shortcut to the :func:`~.expression.cast` function. + + .. versionadded:: 1.0.7 + """ return Cast(self, type_) diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 04e3171a9f..06cb80ba0f 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2040,6 +2040,8 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): 'Incorrect number of expected results') eq_(str(cast(tbl.c.v1, Numeric).compile(dialect=dialect)), 'CAST(casttest.v1 AS %s)' % expected_results[0]) + eq_(str(tbl.c.v1.cast(Numeric).compile(dialect=dialect)), + 'CAST(casttest.v1 AS %s)' % expected_results[0]) eq_(str(cast(tbl.c.v1, Numeric(12, 9)).compile(dialect=dialect)), 'CAST(casttest.v1 AS %s)' % expected_results[1]) eq_(str(cast(tbl.c.ts, Date).compile(dialect=dialect)), diff --git a/test/sql/test_type_expressions.py b/test/sql/test_type_expressions.py index c35e9ff538..574edfe9e8 100644 --- a/test/sql/test_type_expressions.py +++ b/test/sql/test_type_expressions.py @@ -40,13 +40,6 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): "SELECT CAST(test_table.y AS VARCHAR) AS anon_1 FROM test_table" ) - def test_cast_method(self): - table = self._fixture() - self.assert_compile( - select([table.c.y.cast(String)]), - "SELECT CAST(test_table.y AS VARCHAR) AS anon_1 FROM test_table" - ) - def test_select_cols_use_labels(self): table = self._fixture()