diff --git a/docs/changelog.rst b/docs/changelog.rst index e8d3d574..c3c6340f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,7 @@ Changelog Changes in 0.8 ============== +- Deprecated `get_or_create` (MongoEngine/mongoengine#35) - Updated inheritable objects created by upsert now contain _cls (MongoEngine/mongoengine#118) - Added support for creating documents with embedded documents in a single operation (MongoEngine/mongoengine#6) - Added to_json and from_json to Document (MongoEngine/mongoengine#1) diff --git a/mongoengine/queryset/queryset.py b/mongoengine/queryset/queryset.py index bfd15a8c..dde7d55e 100644 --- a/mongoengine/queryset/queryset.py +++ b/mongoengine/queryset/queryset.py @@ -232,10 +232,11 @@ class QuerySet(object): dictionary of default values for the new document may be provided as a keyword argument called :attr:`defaults`. - .. warning:: This requires two separate operations and therefore a + .. note:: This requires two separate operations and therefore a race condition exists. Because there are no transactions in mongoDB other approaches should be investigated, to ensure you - don't accidently duplicate data when using this method. + don't accidently duplicate data when using this method. This is + now scheduled to be removed before 1.0 :param write_options: optional extra keyword arguments used if we have to create a new document. @@ -244,9 +245,14 @@ class QuerySet(object): :param auto_save: if the object is to be saved automatically if not found. + .. deprecated:: 0.8 .. versionchanged:: 0.6 - added `auto_save` .. versionadded:: 0.3 """ + msg = ("get_or_create is scheduled to be deprecated. The approach is " + "flawed without transactions. Upserts should be preferred.") + raise DeprecationWarning(msg) + defaults = query.get('defaults', {}) if 'defaults' in query: del query['defaults']