From afd78a37dafe8e84e23bccfb570bd758797e2142 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 13 Jan 2017 12:43:24 -0500 Subject: Use full column->type processing for ON CONFLICT SET clause Fixed bug in new "ON CONFLICT DO UPDATE" feature where the "set" values for the UPDATE clause would not be subject to type-level processing, as normally takes effect to handle both user-defined type level conversions as well as dialect-required conversions, such as those required for JSON datatypes. Additionally, clarified that the keys in the set_ dictionary should match the "key" of the column, if distinct from the column name. A warning is emitted for remaining column names that don't match column keys; for compatibility reasons, these are emitted as they were previously. Fixes: #3888 Change-Id: I67a04c67aa5f65e6d29f27bf3ef2f8257088d073 --- lib/sqlalchemy/dialects/postgresql/dml.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects/postgresql/dml.py') diff --git a/lib/sqlalchemy/dialects/postgresql/dml.py b/lib/sqlalchemy/dialects/postgresql/dml.py index df53fa8a2..bfdfbfa36 100644 --- a/lib/sqlalchemy/dialects/postgresql/dml.py +++ b/lib/sqlalchemy/dialects/postgresql/dml.py @@ -70,6 +70,8 @@ class Insert(StandardInsert): Required argument. A dictionary or other mapping object with column names as keys and expressions or literals as values, specifying the ``SET`` actions to take. + If the target :class:`.Column` specifies a ".key" attribute distinct + from the column name, that key should be used. .. warning:: This dictionary does **not** take into account Python-specified default UPDATE values or generation functions, @@ -205,7 +207,7 @@ class OnConflictDoUpdate(OnConflictClause): if (not isinstance(set_, dict) or not set_): raise ValueError("set parameter must be a non-empty dictionary") self.update_values_to_set = [ - (key, _literal_as_binds(value)) + (key, value) for key, value in set_.items() ] self.update_whereclause = where -- cgit v1.2.1