Skip to content

Refetching an object doesn't refresh what's in the session when expire_on_commit=False #6244

Answered by zzzeek
ljiatu asked this question in Usage Questions
Discussion options

You must be logged in to vote

yes this is expected.

Database transactions are isolated so based on the isolation configuration of the database in use, it might not be possible for an ongoing transaction to "see" what's been committed outside of that transaction since it started.

In your example above, you in fact are committing both transactions, so when you begin a second transaction on the original Session, you would be able to see these changes from a database perspective. But you set expire_on_commit=False, which means that even though you've committed your work, the objects within that Session are non-expired and will not refresh by default, even if a new SELECT statement is emitted that touches them.

To have the…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ljiatu
Comment options

@ljiatu
Comment options

@zzzeek
Comment options

@ljiatu
Comment options

Answer selected by ljiatu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants