]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Merge branch 'master' into ticket_3100
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Nov 2014 22:43:01 +0000 (17:43 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Nov 2014 22:43:01 +0000 (17:43 -0500)
Conflicts:
lib/sqlalchemy/orm/persistence.py

1  2 
lib/sqlalchemy/orm/persistence.py

index c4a9402fbc4318740f9dcd0c1f0e4a317d5a58be,6b8d5af14578335b2256a09b7a3a7fa9b4f2004c..81024c41f192bbd6c10e1493855ddcfdd9c3aba5
@@@ -467,39 -357,30 +467,39 @@@ def _collect_update_commands
          if not (params or value_params):
              continue
  
 -        pk_params = {}
 -        for col in pks:
 -            propkey = mapper._columntoproperty[col].key
 -            history = state.manager[propkey].impl.get_history(
 -                state, state_dict, attributes.PASSIVE_OFF)
 -
 -            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)
 +        if bulk:
 +            pk_params = dict(
 +                (propkey_to_col[propkey]._label, state_dict.get(propkey))
 +                for propkey in
 +                set(propkey_to_col).
 +                intersection(mapper._pk_keys_by_table[table])
 +            )
 +        else:
 +            pk_params = {}
 +            for col in pks:
 +                propkey = mapper._columntoproperty[col].key
 +
 +                history = state.manager[propkey].impl.get_history(
 +                    state, state_dict, attributes.PASSIVE_OFF)
 +
 +                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:
 -                    # 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 pk_params[col._label] is None:
 -                raise orm_exc.FlushError(
 -                    "Can't update table %s using NULL for primary "
 -                    "key value on column %s" % (table, col))
 +                    pk_params[col._label] = history.unchanged[0]
++                if pk_params[col._label] is None:
++                    raise orm_exc.FlushError(
++                        "Can't update table %s using NULL for primary "
++                        "key value on column %s" % (table, col))
  
          if params or value_params:
-             if None in pk_params.values():
-                 raise orm_exc.FlushError(
-                     "Can't update table using NULL for primary "
-                     "key value")
              params.update(pk_params)
              yield (
                  state, state_dict, params, mapper,