diff options
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 5 | ||||
-rw-r--r-- | test/sql/test_compiler.py | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index f6881f958..e0303e2fa 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -7,6 +7,13 @@ :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 152e68e34..59e46de12 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 e8fea2f7a..3b8aed23f 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 ()") |