Using bulk_update_mappings when the primary key column has a distinct key 
and name seems to cause an error. Specifically, running this code:

from __future__ import unicode_literals

import os

from sqlalchemy import create_engine, Column, Integer, Unicode
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, relationship


Base = declarative_base()

class Person(Base):
    __tablename__ = "person"

    id = Column(Integer, primary_key=True, name="person_id")
    name = Column(Unicode, nullable=False)

    def __repr__(self):
        return "Person(id={!r}, name={!r})".format(self.id, self.name)


engine = create_engine("sqlite:///:memory:")

Base.metadata.create_all(engine)
session = Session(engine)

person = Person(name="Bob")
session.add(person)
session.commit()
session.bulk_update_mappings(Person, [{"id": person.id, "name": "Jim"}])
session.commit()

assert session.query(Person).get(person.id).name == "Jim"

produces the error:

sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A value 
is required for bind parameter 'person_person_id' [SQL: u'UPDATE person SET 
person_id=?, name=? WHERE person.person_id = ?'] [parameters: 
[{'person_id': 1, 'name': u'Jim'}]]

Am I missing something, or is this a bug? Or just not an intended use-case 
of bulk_updating_mappings? Setting the name of the column to "id" seems to 
work, as does setting the name column to have a distinct name.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to