summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorAlejandro <tovarich@gmail.com>2016-01-06 19:36:10 -0300
committerRaphaƫl Barrois <raphael.barrois@polytechnique.org>2016-01-07 01:38:05 +0100
commit4172dd686ce483191b33e3189d716f11b3da921e (patch)
treedb2b5633ff9a6e3ed21e4206733238ade2ce4bf7 /factory
parent28ce31db61a46fbd73126630c758d32a7245da42 (diff)
downloadfactory-boy-4172dd686ce483191b33e3189d716f11b3da921e.tar
factory-boy-4172dd686ce483191b33e3189d716f11b3da921e.tar.gz
optional forced flush on SQLAlchemyModelFactory
fixes rbarrois/factory_boy#81
Diffstat (limited to 'factory')
-rw-r--r--factory/alchemy.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/factory/alchemy.py b/factory/alchemy.py
index 20da6cf..a9aab23 100644
--- a/factory/alchemy.py
+++ b/factory/alchemy.py
@@ -27,6 +27,7 @@ class SQLAlchemyOptions(base.FactoryOptions):
def _build_default_options(self):
return super(SQLAlchemyOptions, self)._build_default_options() + [
base.OptionDefault('sqlalchemy_session', None, inherit=True),
+ base.OptionDefault('force_flush', False, inherit=True),
]
@@ -43,4 +44,6 @@ class SQLAlchemyModelFactory(base.Factory):
session = cls._meta.sqlalchemy_session
obj = model_class(*args, **kwargs)
session.add(obj)
+ if cls._meta.force_flush:
+ session.flush()
return obj