Minor text and comments enhancements

This commit is contained in:
mrigal 2015-04-12 12:29:25 +02:00 committed by Matthieu Rigal
parent 33b1eed361
commit 76adb13a64
3 changed files with 9 additions and 4 deletions

View File

@ -166,7 +166,7 @@ class Document(BaseDocument):
@classmethod @classmethod
def _get_collection(cls): def _get_collection(cls):
"""Returns the collection for the document.""" """Returns the collection for the document."""
#TODO: use new get_collection() with PyMongo3 ? # TODO: use new get_collection() with PyMongo3 ?
if not hasattr(cls, '_collection') or cls._collection is None: if not hasattr(cls, '_collection') or cls._collection is None:
db = cls._get_db() db = cls._get_db()
collection_name = cls._get_collection_name() collection_name = cls._get_collection_name()
@ -308,7 +308,9 @@ class Document(BaseDocument):
object_id = collection.insert(doc, **write_concern) object_id = collection.insert(doc, **write_concern)
else: else:
object_id = collection.save(doc, **write_concern) object_id = collection.save(doc, **write_concern)
# Pymongo 3.0 bug, fix scheduled for 3.0.1 # TODO: Pymongo 3.0 bug, fix scheduled for 3.0.1
# In PyMongo 3.0, the save() call calls internally the _update() call
# but they forget to return the _id value passed back, therefore getting it back here
if not object_id and pymongo.version_tuple == (3, 0): if not object_id and pymongo.version_tuple == (3, 0):
object_id = self._qs.filter(**self._object_key).first() and \ object_id = self._qs.filter(**self._object_key).first() and \
self._qs.filter(**self._object_key).first().pk self._qs.filter(**self._object_key).first().pk

View File

@ -930,6 +930,7 @@ class BaseQuerySet(object):
plan = pprint.pformat(plan) plan = pprint.pformat(plan)
return plan return plan
# DEPRECATED. Has no more impact on PyMongo 3+
def snapshot(self, enabled): def snapshot(self, enabled):
"""Enable or disable snapshot mode when querying. """Enable or disable snapshot mode when querying.
@ -1419,7 +1420,8 @@ class BaseQuerySet(object):
cursor_args['slave_okay'] = self._slave_okay cursor_args['slave_okay'] = self._slave_okay
else: else:
fields_name = 'projection' fields_name = 'projection'
# snapshot seems not to be handled at all by PyMongo 3+ # snapshot is not to handled at all by PyMongo 3+
# TODO: raise a warning?
cursor_args = { cursor_args = {
'no_cursor_timeout': self._timeout 'no_cursor_timeout': self._timeout
} }

View File

@ -2491,7 +2491,8 @@ class FieldTest(unittest.TestCase):
binary_id = uuid.uuid4().bytes binary_id = uuid.uuid4().bytes
att = Attachment(id=binary_id).save() att = Attachment(id=binary_id).save()
self.assertEqual(1, Attachment.objects.count()) self.assertEqual(1, Attachment.objects.count())
self.assertNotEqual(None, Attachment.objects.filter(id=binary_id).first()) # TODO use assertIsNotNone once Python 2.6 support is dropped
self.assertFalse(Attachment.objects.filter(id=binary_id).first() is not None)
att.delete() att.delete()
self.assertEqual(0, Attachment.objects.count()) self.assertEqual(0, Attachment.objects.count())