post_update does not honor many-to-one assign to None w/o active history

Issue #3599 resolved
Mike Bayer repo owner created an issue
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(ForeignKey('a.id'))
    a = relationship(
        "A",
        # no UPDATE is emitted at the end unless this is
        # commented out
        post_update=True
    )

e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)

s = Session(e)
s.add(B(a=A()))
s.commit()

b1 = s.query(B).first()
b1.a = None
s.commit()

b1 = s.query(B).first()
assert b1.a is None

Comments (2)

  1. Mike Bayer reporter
    • Fixed issue where post_update on a many-to-one relationship would fail to emit an UPDATE in the case where the attribute were set to None and not previously loaded. fixes #3599

    → <<cset 935bc34dc50d>>

  2. Log in to comment