deferred column_property gets set to "expired" state on flush, unconditionally loads on unexpire

Issue #3984 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)
    a = Column(Integer)
    b = Column(Integer)

    aplusb = column_property(
        a + b, deferred=True
    )

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

s = Session(e)
s.add(A(a=1, b=2))
s.commit()

a1 = s.query(A).first()
assert 'aplusb' not in a1.__dict__
a1.b = 5
s.flush()
s.commit()
a1.b
assert 'aplusb' not in a1.__dict__

Comments (2)

  1. Mike Bayer reporter

    Add conditionals specific to deferred for expire ro properties

    Fixed bug where a :func:.column_property that is also marked as "deferred" would be marked as "expired" during a flush, causing it to be loaded along with the unexpiry of regular attributes even though this attribute was never accessed.

    Change-Id: Iaa9e17b66ece30a8e729e4af746b31ff99b1ec9a Fixes: #3984

    → <<cset c4f28097aa6a>>

  2. Log in to comment