From b2df5be7ee8b5ee7ae67323b5018ca37bbf0ce2a Mon Sep 17 00:00:00 2001 From: jonathan vanasco Date: Mon, 27 Sep 2021 15:15:33 -0400 Subject: Deprecate create_engine.implicit_returning The :paramref:`_sa.create_engine.implicit_returning` parameter is deprecated on the :func:`_sa.create_engine` function only; the parameter remains available on the :class:`_schema.Table` object. This parameter was originally intended to enable the "implicit returning" feature of SQLAlchemy when it was first developed and was not enabled by default. Under modern use, there's no reason this parameter should be disabled, and it has been observed to cause confusion as it degrades performance and makes it more difficult for the ORM to retrieve recently inserted server defaults. The parameter remains available on :class:`_schema.Table` to specifically suit database-level edge cases which make RETURNING infeasible, the sole example currently being SQL Server's limitation that INSERT RETURNING may not be used on a table that has INSERT triggers on it. Also removed from the Oracle dialect some logic that would upgrade an Oracle 8/8i server version to use implicit returning if the parameter were explictly passed; these versions of Oracle still support RETURNING so the feature is now enabled for all Oracle versions. Fixes: #6962 Change-Id: Ib338e300cd7c8026c3083043f645084a8211aed8 --- lib/sqlalchemy/testing/assertsql.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/testing/assertsql.py') diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py index ca0bc6726..9816c99b7 100644 --- a/lib/sqlalchemy/testing/assertsql.py +++ b/lib/sqlalchemy/testing/assertsql.py @@ -186,7 +186,9 @@ class CompiledSQL(SQLMatchRule): self.is_consumed = True self.errormessage = None else: - self.errormessage = self._failure_message(params) % { + self.errormessage = self._failure_message( + execute_observed, params + ) % { "received_statement": _received_statement, "received_parameters": _received_parameters, } @@ -203,7 +205,7 @@ class CompiledSQL(SQLMatchRule): else: return None - def _failure_message(self, expected_params): + def _failure_message(self, execute_observed, expected_params): return ( "Testing for compiled statement\n%r partial params %s, " "received\n%%(received_statement)r with params " @@ -223,7 +225,7 @@ class RegexSQL(CompiledSQL): self.params = params self.dialect = dialect - def _failure_message(self, expected_params): + def _failure_message(self, execute_observed, expected_params): return ( "Testing for compiled statement ~%r partial params %s, " "received %%(received_statement)r with params " @@ -263,11 +265,8 @@ class DialectSQL(CompiledSQL): return received_stmt, execute_observed.context.compiled_parameters - def _compare_sql(self, execute_observed, received_statement): + def _dialect_adjusted_statement(self, paramstyle): stmt = re.sub(r"[\n\t]", "", self.statement) - # convert our comparison statement to have the - # paramstyle of the received - paramstyle = execute_observed.context.dialect.paramstyle if paramstyle == "pyformat": stmt = re.sub(r":([\w_]+)", r"%(\1)s", stmt) else: @@ -280,9 +279,27 @@ class DialectSQL(CompiledSQL): elif paramstyle == "numeric": repl = None stmt = re.sub(r":([\w_]+)", repl, stmt) + return stmt + def _compare_sql(self, execute_observed, received_statement): + paramstyle = execute_observed.context.dialect.paramstyle + stmt = self._dialect_adjusted_statement(paramstyle) return received_statement == stmt + def _failure_message(self, execute_observed, expected_params): + paramstyle = execute_observed.context.dialect.paramstyle + return ( + "Testing for compiled statement\n%r partial params %s, " + "received\n%%(received_statement)r with params " + "%%(received_parameters)r" + % ( + self._dialect_adjusted_statement(paramstyle).replace( + "%", "%%" + ), + repr(expected_params).replace("%", "%%"), + ) + ) + class CountStatements(AssertRule): def __init__(self, count): -- cgit v1.2.1