From ae495c69adacdd341d4ab22df4eedbbc6cb9df8e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 22 Apr 2010 11:24:25 -0400 Subject: [PATCH] - Fixed bug that prevented implicit RETURNING from functioning properly with composite primary key that contained zeroes. [ticket:1778] --- CHANGES | 5 +++++ lib/sqlalchemy/engine/default.py | 11 ++++++++--- test/sql/test_query.py | 9 +++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 4f853b2900..01283843f4 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,11 @@ CHANGES ======= 0.6.1 ===== +- sql + - Fixed bug that prevented implicit RETURNING from functioning + properly with composite primary key that contained zeroes. + [ticket:1778] + - oracle - Added a check for cx_oracle versions lower than version 5, in which case the incompatible "output type handler" won't diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index fc49c62fac..a8c336336e 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -576,9 +576,14 @@ class DefaultExecutionContext(base.ExecutionContext): table = self.compiled.statement.table row = resultproxy.fetchone() - self._inserted_primary_key = [v is not None and v or row[c] - for c, v in zip(table.primary_key, self._inserted_primary_key) - ] + ipk = [] + for c, v in zip(table.primary_key, self._inserted_primary_key): + if v is not None: + ipk.append(v) + else: + ipk.append(row[c]) + + self._inserted_primary_key = ipk def last_inserted_params(self): return self._last_inserted_params diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 80d524bf12..5a4f033112 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -160,6 +160,15 @@ class QueryTest(TestBase): {'id':'id1'}, {'id':'id1', 'bar':'hi'}, ), + ( + {'unsupported':['sqlite']}, + Table("t6", metadata, + Column('id', Integer, primary_key=True, test_needs_autoincrement=True), + Column('bar', Integer, primary_key=True) + ), + {'bar':0}, + {'id':1, 'bar':0}, + ), ]: if testing.db.name in supported['unsupported']: continue -- 2.47.3