1. Michael Bayer
  2. sqlalchemy

Issues

Issue #3139 resolved

expunge after delete() fails

Michael Bayer
repo owner created an issue
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, object_session

Base = declarative_base()

class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    name = Column(String)


if __name__ == "__main__":
    engine = create_engine("sqlite:///:memory:", echo=False)
    Base.metadata.create_all(engine)
    Session = sessionmaker(bind=engine)
    session = Session()

    ed = User(name="ed")

    session.add(ed)

    session.flush()

    session.delete(ed)

    session.flush()

    # should raise, or otherwise actually expunge
    session.expunge(ed)

    assert object_session(ed) is None
    assert ed not in session

Comments (3)

  1. Michael Bayer reporter
    • Fixed bug where :meth:.Session.expunge would not fully detach the given object if the object had been subject to a delete operation that was flushed, but not committed. This would also affect related operations like :func:.make_transient. fixes #3139

    → <<cset 38bc8098419d>>

  2. Log in to comment