summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-05 23:12:10 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-05 23:12:10 +0100
commit114ac649e448e97a210cf8dccc6ba50278645ce6 (patch)
tree705da01544a66d5602624d4d3813ac7ffef45382 /factory
parentd01f5e6c041395bc579f58e12e7034a08afe3f14 (diff)
downloadfactory-boy-114ac649e448e97a210cf8dccc6ba50278645ce6.tar
factory-boy-114ac649e448e97a210cf8dccc6ba50278645ce6.tar.gz
Stop calling Foo.objects.create() when it doesn't break (Closes #23).
This will be properly fixed in v2.0.0; the current heuristic is: - If the user defined a custom _create method, use it - If he didn't, but the associated class has a objects attribute, use TheClass.objects.create(*args, **kwargs) - Otherwise, simply call TheClass(*args, **kwargs). Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory')
-rw-r--r--factory/base.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/factory/base.py b/factory/base.py
index 3ebc746..44d58a7 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -527,7 +527,8 @@ class Factory(BaseFactory):
creation_function = getattr(cls, '_creation_function', ())
if creation_function and creation_function[0]:
return creation_function[0]
- elif cls._create.__func__ == Factory._create.__func__:
+ elif cls._create.__func__ == Factory._create.__func__ and \
+ hasattr(cls._associated_class, 'objects'):
# Backwards compatibility.
# Default creation_function and default _create() behavior.
# The best "Vanilla" _create detection algorithm I found is relying