charlatan icon indicating copy to clipboard operation
charlatan copied to clipboard

InstallAndSave builder should allow deferring transaction commit

Open bijanvakili opened this issue 9 years ago • 1 comments

The default SQLAlchemy builder (InstallAndSave) commits the session on each individual fixture.

In some cases, it may be more desirable to allow all fixtures to be instantiated added to the session before committing the entire session. For example, if any semantic error occurs (valid YAML, but invalid for the SQLAlchemy model), the application may wish to roll back all fixture changes rather than commit partial data.

This could be done by adding a autocommit boolean kwarg to the __call__ method that would skip this session commit call.

bijanvakili avatar Sep 04 '16 19:09 bijanvakili

It's possible to add this flag but then the hooks need to be refactored too - you no longer save an instance immediately, you probably want to register somewhere / defer the calls to before_save/after_save. It's easier to just implement your own version of Builder (that's what I do).

aomelianenko avatar Oct 15 '16 19:10 aomelianenko