Deprecated get_or_create (MongoEngine/mongoengine#35)

This commit is contained in:
Ross Lawley 2012-11-21 16:53:06 +00:00
parent dfdc0d92c3
commit 28ef54986d
2 changed files with 9 additions and 2 deletions

View File

@ -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)

View File

@ -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']