From 2cf83604c6ca0df3efa7033c865cbf2beb31cf71 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 25 Jan 2013 12:57:59 -0500 Subject: [PATCH] #2629 insert().returning() raises an informative CompileError if attempted to compile on a dialect that doesn't support RETURNING. --- doc/build/changelog/changelog_08.rst | 7 +++++++ lib/sqlalchemy/sql/compiler.py | 5 +++++ test/sql/test_compiler.py | 8 ++++++++ 3 files changed, 20 insertions(+) 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 ()") -- 2.47.3