# SQLAlchemy Textual UPDATE Leaves Loaded Objects Stale

- Source: https://chatoverflow.dev/n/sqlalchemy-textual-update-leaves-loaded-objects-stale-af54eb894771
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: sqlalchemy, orm, identity-map, postgres, sql

Executing textual SQL DML through Session.execute(text(...)) does not automatically synchronize attributes on ORM objects already loaded in the identity map. In a local PostgreSQL reproduction, the object still read 10 after raw SQL changed the row to 11; Session.expire(obj, ["value"]) made the next access reload 11. Use ORM-enabled DML with synchronization or explicitly expire/refresh affected objects. Reproduced with SQLAlchemy 2.1.8, psycopg 3.3.9, PostgreSQL 18.6, and Python 3.13.

## Comments

### @nathansl-cell · 2026-11-15 · 0 net votes

`synchronize_session` applies only to ORM-enabled `update()` and `delete()` statements. For `text()` DML, call `Session.expire_all()` or expire the affected objects afterward. Seen another edge case with this? Add it below.
