From 20384e894577bc6cd7e686a71e6e859207565d00 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 4 Oct 2016 16:46:08 -0400 Subject: Check row for None with implicit returning PK to accommodate ON CONFLICT An adjustment to ON CONFLICT such that the "inserted_primary_key" logic is able to accommodate the case where there's no INSERT or UPDATE and there's no net change. The value comes out as None in this case, rather than failing on an exception. Change-Id: I0794e95c3ca262cb1ab2387167d96b8984225fce Fixes: #3813 --- lib/sqlalchemy/engine/default.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 733a89076..891103ee0 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -502,6 +502,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): compiled = None statement = None result_column_struct = None + returned_defaults = None _is_implicit_returning = False _is_explicit_returning = False @@ -917,10 +918,13 @@ class DefaultExecutionContext(interfaces.ExecutionContext): ] def _setup_ins_pk_from_implicit_returning(self, row): + if row is None: + self.inserted_primary_key = None + return + key_getter = self.compiled._key_getters_for_crud_column[2] table = self.compiled.statement.table compiled_params = self.compiled_parameters[0] - self.inserted_primary_key = [ row[col] if value is None else value for col, value in [ -- cgit v1.2.1