create() method doesn't save model
I have factory
import factory
class GroupFactory(factory.Factory):
FACTORY_FOR = Group
remote_id = factory.Sequence(lambda n: n)
Method create doesn't save model, I should call it especially:
In [1]: from vkontakte_groups.factories import GroupFactory
In [2]: group = GroupFactory.create()
In [3]: group.id, group.pk
Out[3]: (None, None)
In [4]: group.save()
In [5]: group.id, group.pk
Out[5]: (890, 890)
In [6]: import factory
In [7]: factory.__version__
Out[7]: '2.1.0-dev'
That is very strange. Before it was behaviour with saving by default and I don't know what was changed.. Should I post here more environment settings?
The ".create() calls save()" behavior changed from version 2.0.0 ; it was deprecated since version 1.3.0 (including deprecation warnings ; see the ChangeLog).
For Django factories, you should inherit from factory.DjangoModelFactory; it provides the following benefits:
- Automatic call to
.create() - Ability to use some fields for a
get_or_createcall - Automatic
save()after post-generation hooks ran
More details on the DjangoModelFactory documentation
Thanks. It's completely solve my issue
Could we document the ORM Factories in the README in like a section called Supported ORMs or something to make it more obvious we should use a different factory subclass? This took a little while to figure out and is a pretty fundamental change from 1.3.
@yellottyellott That's a very good point, I'll do it right away.
XD!