auto-key-validation in mappedcollection bulk set is inconsistent vs. single item set

Issue #3604 new
Mike Bayer repo owner created an issue

e.g. make setitem and set symmetric; if users want validation that would be a separate event. partial patch forthcoming

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.collections import attribute_mapped_collection

Base = declarative_base()


class A(Base):
    __tablename__ = 'a'
    id = Column(Integer, primary_key=True)
    bs = relationship("B", collection_class=attribute_mapped_collection("key"))


class B(Base):
    __tablename__ = 'b'
    id = Column(Integer, primary_key=True)
    key = Column(String)
    a_id = Column(ForeignKey('a.id'))

    def __repr__(self):
        return "B(%s)" % id(self)

a1 = A()

b1 = B(key='foo')
b2 = B(key='foo')


a1.bs['foo'] = b1
a1.bs['bar'] = b2

print a1.bs

a1 = A()
a1.bs = {"foo": b1, "bar": b2}

print a1.bs

Comments (4)

  1. Log in to comment