Skip to content

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

@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Michael Bayer (@zzzeek)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions