From 0a67c1305266ba9c4558e371fa9b193788c65bea Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 22 May 2017 14:47:26 -0400 Subject: Detect no params w/ manual version_id counter and set to itself Fixed bug where programmatic version_id counter in conjunction with joined table inheritance would fail if the version_id counter were not actually incremented and no other values on the base table were modified, as the UPDATE would have an empty SET clause. Since programmatic version_id where version counter is not incremented is a documented use case, this specific condition is now detected and the UPDATE now sets the version_id value to itself, so that concurrency checks still take place. Change-Id: I80e385bffeed4851cc20131cbe983c173a46f655 Fixes: #3996 --- lib/sqlalchemy/orm/persistence.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py index 588a1d696..86125d6f2 100644 --- a/lib/sqlalchemy/orm/persistence.py +++ b/lib/sqlalchemy/orm/persistence.py @@ -511,12 +511,19 @@ def _collect_update_commands( continue col = mapper.version_id_col + no_params = not params and not value_params params[col._label] = update_version_id if (bulk or col.key not in params) and \ mapper.version_id_generator is not False: val = mapper.version_id_generator(update_version_id) params[col.key] = val + elif mapper.version_id_generator is False and no_params: + # no version id generator, no values set on the table, + # and version id wasn't manually incremented. + # set version id to itself so we get an UPDATE + # statement + params[col.key] = update_version_id elif not (params or value_params): continue -- cgit v1.2.1