From: Mike Bayer Date: Fri, 25 Jan 2013 17:57:59 +0000 (-0500) Subject: #2629 X-Git-Tag: rel_0_8_0~27^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cf83604c6ca0df3efa7033c865cbf2beb31cf71;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git #2629 insert().returning() raises an informative CompileError if attempted to compile on a dialect that doesn't support RETURNING. --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index f6881f9583..e0303e2faf 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,13 @@ .. changelog:: :version: 0.8.0 + .. change:: + :tags: sql, bug + :tickets: 2629 + + insert().returning() raises an informative CompileError if attempted + to compile on a dialect that doesn't support RETURNING. + .. change:: :tags: orm, bug :tickets: 2655 diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 152e68e34f..59e46de122 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1248,6 +1248,11 @@ class SQLCompiler(engine.Compiled): else: return "" + def returning_clause(self, stmt, returning_cols): + raise exc.CompileError( + "RETURNING is not supported by this " + "dialect's statement compiler.") + def limit_clause(self, select): text = "" if select._limit is not None: diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index e8fea2f7aa..3b8aed23f6 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2553,6 +2553,14 @@ class CRUDTest(fixtures.TestBase, AssertsCompiledSQL): table.insert(inline=True), "INSERT INTO sometable (foo) VALUES (foobar())", params={}) + def test_insert_returning_not_in_default(self): + stmt = table1.insert().returning(table1.c.myid) + assert_raises_message( + exc.CompileError, + "RETURNING is not supported by this dialect's statement compiler.", + stmt.compile + ) + def test_empty_insert_default(self): stmt = table1.insert().values({}) # hide from 2to3 self.assert_compile(stmt, "INSERT INTO mytable () VALUES ()")