-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Closed
Copy link
Labels
bugSomething isn't workingSomething isn't workinggreat mcveAn issue with a great mcveAn issue with a great mcveorm
Milestone
Description
This was discussed in #11911
The server_onupdate columns do not get expired by the orm following an update, requiring populate-existing to fetch the new values. This impact mainly computed columns.
Reproducer:
from sqlalchemy import orm
import sqlalchemy as sa
class Base(orm.DeclarativeBase):
pass
class T(Base):
__tablename__ = "t"
id: orm.Mapped[int] = orm.mapped_column(primary_key=True)
value: orm.Mapped[int]
cc: orm.Mapped[int] = orm.mapped_column(sa.Computed("value + 42"))
e = sa.create_engine("sqlite:///", echo=True)
Base.metadata.create_all(e)
with orm.Session(e) as s:
s.add(T(value=10))
s.flush()
s.commit()
with orm.Session(e) as s:
assert (v := s.get_one(T, 1)).cc == 52
s.execute(sa.update(T).values(id=1, value=2))
assert (v := s.get_one(T, 1)).cc != 44 # should be 44
with orm.Session(e) as s:
assert (v := s.get_one(T, 1)).cc == 52
r = s.execute(sa.update(T).values(value=2).returning(T))
assert (v := r.scalar_one()).cc != 44 # should be 44
assert (v := s.get_one(T, 1)).cc != 44 # should be 44
with orm.Session(e) as s:
r = s.execute(sa.insert(T).values(value=9).returning(T))
assert (v := r.scalar_one()).cc == 51
r = s.execute(sa.update(T).values(value=2).filter_by(id=2).returning(T))
assert (v := r.scalar_one()).cc != 44 # should be 44
r = s.execute(sa.select(T).filter_by(id=2))
assert (v := r.scalar_one()).cc != 44 # should be 44Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggreat mcveAn issue with a great mcveAn issue with a great mcveorm