]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- simplify PK logic in update for row switch
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Aug 2014 20:14:57 +0000 (16:14 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Aug 2014 21:43:50 +0000 (17:43 -0400)
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/persistence.py

index 89c092b580cc5f5921c2e9836627b4275d9ba0e8..f22cac329cead928be0d078862f396132235a345 100644 (file)
@@ -2364,6 +2364,9 @@ class Mapper(InspectionAttr):
 
     @_memoized_configured_property
     def _primary_key_props(self):
+        # TODO: this should really be called "identity key props",
+        # as it does not necessarily include primary key columns within
+        # individual tables
         return [self._columntoproperty[col] for col in self.primary_key]
 
     def _get_state_attr_by_column(
index e36f87991d470cf1d6b971016c414fac7497995f..37b696d0f9b8dae0f2557c130a6fea71f600a01f 100644 (file)
@@ -362,29 +362,19 @@ def _collect_update_commands(uowtransaction, table, states_to_update):
             history = state.manager[propkey].impl.get_history(
                 state, state_dict, attributes.PASSIVE_OFF)
 
-            if row_switch and not history.deleted and history.added:
-                # row switch present.  convert a row that thought
-                # it would be an INSERT into an UPDATE, by removing
-                # the PK value from the SET clause and instead putting
-                # it in the WHERE clause.
-                del params[col.key]
-                pk_params[col._label] = history.added[0]
-            elif history.added:
-                # we're updating the PK value.
-                assert history.deleted, (
-                    "New PK value without an old one not "
-                    "possible for an UPDATE")
-                # check if an UPDATE of the PK value
-                # has already occurred as a result of ON UPDATE CASCADE.
-                # If so, use the new value to locate the row.
-                if ("pk_cascaded", state, col) in uowtransaction.attributes:
+            if history.added:
+                if not history.deleted or \
+                    ("pk_cascaded", state, col) in uowtransaction.attributes:
                     pk_params[col._label] = history.added[0]
+                    params.pop(col.key, None)
                 else:
                     # else, use the old value to locate the row
                     pk_params[col._label] = history.deleted[0]
+                    params[col.key] = history.added[0]
             else:
                 pk_params[col._label] = history.unchanged[0]
 
+
         if params or value_params:
             if None in pk_params.values():
                 raise orm_exc.FlushError(