bulk update can't accomodate alt-named primary key (at the attribute level)

Issue #3849 resolved
Mike Bayer repo owner created an issue
diff --git a/test/orm/test_bulk.py b/test/orm/test_bulk.py
index 0a51a5a..07c430f 100644
--- a/test/orm/test_bulk.py
+++ b/test/orm/test_bulk.py
@@ -232,6 +232,61 @@ class BulkUDPostfetchTest(BulkTest, fixtures.MappedTest):
         eq_(a1.y, 2)


+class BulkUDTestAltColKeys(BulkTest, fixtures.MappedTest):
+    @classmethod
+    def define_tables(cls, metadata):
+        Table(
+            'people', metadata,
+            Column(
+                'person_id', Integer,
+                primary_key=True),
+            Column('name', String(50)))
+
+    @classmethod
+    def setup_classes(cls):
+        class Person(cls.Comparable):
+            pass
+
+    @classmethod
+    def setup_mappers(cls):
+        Person = cls.classes.Person
+        people = cls.tables.people
+
+        mapper(Person, people, properties={
+            'id': people.c.person_id,
+            'personname': people.c.name
+        })
+
+    def test_insert(self):
+        Person = self.classes.Person
+
+        s = Session()
+        s.bulk_insert_mappings(
+            Person, [{"id": 5, "personname": "thename"}]
+        )
+
+        eq_(
+            s.query(Person).first(),
+            Person(id=5, personname="thename")
+        )
+
+    def test_update(self):
+        Person = self.classes.Person
+
+        s = Session()
+        s.add(Person(id=5, personname="thename"))
+        s.commit()
+
+        s.bulk_update_mappings(
+            Person, [{"id": 5, "personname": "newname"}]
+        )
+
+        eq_(
+            s.query(Person).first(),
+            Person(id=5, personname="newname")
+        )
+
+
 class BulkInheritanceTest(BulkTest, fixtures.MappedTest):
     @classmethod
     def define_tables(cls, metadata):
StatementError: (sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'people_person_id' [SQL: u'UPDATE people SET person_id=?, name=? WHERE people.person_id = ?'] [parameters: [{'person_id': 5, 'name': 'newname'}]]

fortunately there's no workaround so this is safe for immediate release + 1.0.x backport

Comments (4)

  1. Mike Bayer reporter

    Ensure attribute keys used for bulk update pk set

    Fixed bug in :meth:.Session.bulk_update_mappings where an alternate-named primary key attribute would not track properly into the UPDATE statement.

    Change-Id: I33e9140f45827772768fa548adcfeb4dbfc2208d Fixes: #3849

    → <<cset 6a688b736429>>

  2. Log in to comment