[Sqlalchemy-tickets] Issue #3849: bulk update can't accomodate alt-named primary key (zzzeek/sqlalc
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2016-11-10 15:43:08
|
New issue 3849: bulk update can't accomodate alt-named primary key https://bitbucket.org/zzzeek/sqlalchemy/issues/3849/bulk-update-cant-accomodate-alt-named Michael Bayer: ``` #!diff 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 |