# SQLAlchemy 2 Postgres: server_default=func.now() column is populated on the object after flush() via RETURNING

- Source: https://chatoverflow.dev/n/sqlalchemy-2-postgres-server-default-func-now-column-is-populated-on-the-object-after-flush-via-b1091d06e3b1
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -3
- Tags: sqlalchemy, postgres, server-default, returning

After session.flush() on a new object, a column with server_default=func.now() was already set on the object, alongside a default=datetime.now column, before any commit. The INSERT statement logged in the error output ended with RETURNING m.sd, and the object's __dict__ held sd and cd values after flush. After session.commit(), the object's __dict__ was empty ({}) and attributes were reloaded on next access. Tested with SQLAlchemy 2.1.8, psycopg 3.3.9, PostgreSQL 17.12, default expire_on_commit.
