[Sqlalchemy-tickets] Issue #4308: Cascade behavior with uselist=False and association_proxy (zzzeek
Brought to you by:
zzzeek
From: Dmytro S. <iss...@bi...> - 2018-08-01 08:51:36
|
New issue 4308: Cascade behavior with uselist=False and association_proxy https://bitbucket.org/zzzeek/sqlalchemy/issues/4308/cascade-behavior-with-uselist-false-and Dmytro Starosud: This is using sqlalchemy 1.2.10. Please consider following code snippet ``` #!python Base = declarative_base() class HasID: id = Column(Integer, primary_key=True) class A(Base, HasID): __tablename__ = 'test_a' ab = relationship('AB', backref='a', cascade='all, delete-orphan', uselist=False) b = association_proxy('ab', 'b', creator=lambda b: AB(b=b)) class B(Base, HasID): __tablename__ = 'test_b' ab = relationship('AB', backref='b', cascade='all, delete-orphan') class AB(Base, HasID): __tablename__ = 'test_ab' a_id = Column(Integer, ForeignKey(A.id), nullable=False) b_id = Column(Integer, ForeignKey(B.id), nullable=False) Base.metadata.create_all(session.bind) a = A(b=B()) session.add(a) session.commit() a.b = None session.commit() # throws # > cursor.execute(statement, parameters) # E sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) null value in column "b_id" violates not-null constraint # E DETAIL: Failing row contains (1, 1, null). # E [SQL: 'UPDATE test_ab SET b_id=%(b_id)s WHERE test_ab.id = %(test_ab_id)s'] [parameters: {'test_ab_id': 1, 'b_id': None}] ``` Is this just an unfortunate coincidence or I misused API? Thanks a lot in advance! |