Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autosave on update in SQLAlchemy

SQLAlchemy is autosaving the model objects when their attributes are being changed. Is there any way of disabling this and only save it when I need it?

I know there is a expunge function which detaches object model and therefore it won't be updated, but then i cannot access objects relations.

like image 281
arnau Avatar asked Oct 24 '25 04:10

arnau


1 Answers

Try setting autoflush of your session to False:

session.autoflush = False

This way your changes will not be communicated to the database until you call

session.flush()

and will not be committed until you call

session.commit()

Further information about transaction management can be found in the docs

like image 126
architectonic Avatar answered Oct 27 '25 01:10

architectonic