[Sqlalchemy-tickets] Issue #4171: list assignment does not seem to be affecting remove from previou
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-01-24 15:16:31
|
New issue 4171: list assignment does not seem to be affecting remove from previous object correctly https://bitbucket.org/zzzeek/sqlalchemy/issues/4171/list-assignment-does-not-seem-to-be Michael Bayer: major regression, needs immediate release ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) a_id = Column(Integer, ForeignKey('a.id')) a = relationship('A', backref=backref('bs')) e = create_engine("sqlite://", echo='debug') Base.metadata.create_all(e) session = Session(e) for i in xrange(100): a1 = A() a2 = A() b = B(a=a1) # Set B.a = a1 a2.bs = [b] # ... but then put b onto a2's list session.add_all([a1, a2]) session.commit() print len(a1.bs) ``` a1.bs is not consistently zero, depending on which of a1 or a2 is processed first. list assignment not updating state correctly. http://docs.sqlalchemy.org/en/latest/changelog/migration_12.html#a-validates-method-receives-all-values-on-bulk-collection-set-before-comparison is likely cause |