]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix primary key behaviour in bulk_update
authorPatrick Hayes <pfhayes@gmail.com>
Sat, 13 Jun 2015 18:11:16 +0000 (14:11 -0400)
committerPatrick Hayes <pfhayes@gmail.com>
Sat, 13 Jun 2015 18:11:16 +0000 (14:11 -0400)
commit09485d733131b667813f44eb0b6807b698668ee7
tree6fcb43cc5d0033fef788b52f5897a6862854bb06
parente765c55e8cc71bb3773b86b5260df6cb69aff102
Fix primary key behaviour in bulk_update

Suppose you have a model class with a primary key.

Base = declarative_base()
class User(Base):
  id = Column(BigInteger, primary_key=True)
  name = Column(String)

Previously, running
`bulk_update_mappings(User, {'id': 1, 'name': 'hello'})`
would emit the following:

```UPDATE users SET id=1, name='hello' WHERE id=1```

This is contrary to the stated behaviour, where primary keys are omitted
from the SET clause. Furthermore, this behaviour is harmful, as it
can cause the db engine to lock over-aggresively (at least in Postgres).

With this change, the emitted SQL is:

```UPDATE users SET name='hello' WHERE id=1```
lib/sqlalchemy/orm/persistence.py
test/orm/test_bulk.py