Compare commits

...

5 Commits

Author SHA1 Message Date
erdenezul
cf54d6d6f8 Merge pull request #1967 from erdenezul/bump_version_16_3
bump version 0.16.3
2018-12-06 21:56:31 +08:00
Erdenezul Batmunkh
a03fe234d0 bump version 0.16.3 2018-12-06 16:22:00 +08:00
erdenezul
d88d40cc08 Merge pull request #1966 from tjhall13/1965-fix-position-op-with-nested-list-in-embedded-document
Fix bug #1965 of $position and $push operators do not work with nested list
2018-12-06 14:02:46 +08:00
Trevor Hall
d3b4af116e Add fix to changelog.rst #1965 2018-12-05 23:35:42 -06:00
Trevor Hall
352b23331b Fix bug #1965 of $position and $push operators do not work with list in an EmbeddedDocument. Set key value to joined parts excluding the index at the end. Added test case 2018-12-05 20:18:48 -06:00
5 changed files with 25 additions and 3 deletions

View File

@@ -247,3 +247,4 @@ that much better:
* Erdenezul Batmunkh (https://github.com/erdenezul)
* Andy Yankovsky (https://github.com/werat)
* Bastien Gérard (https://github.com/bagerard)
* Trevor Hall (https://github.com/tjhall13)

View File

@@ -6,6 +6,11 @@ Development
===========
- (Fill this out as you fix issues and develop your features).
=================
Changes in 0.16.3
=================
- Fix $push with $position operator not working with lists in embedded document #1965
=================
Changes in 0.16.2
=================

View File

@@ -23,7 +23,7 @@ __all__ = (list(document.__all__) + list(fields.__all__) +
list(signals.__all__) + list(errors.__all__))
VERSION = (0, 16, 2)
VERSION = (0, 16, 3)
def get_version():

View File

@@ -345,7 +345,7 @@ def update(_doc_cls=None, **update):
value = {key: {'$each': value}}
elif op in ('push', 'pushAll'):
if parts[-1].isdigit():
key = parts[0]
key = '.'.join(parts[0:-1])
position = int(parts[-1])
# $position expects an iterable. If pushing a single value,
# wrap it in a list.

View File

@@ -842,10 +842,16 @@ class InstanceTest(MongoDBTestCase):
@requires_mongodb_gte_26
def test_modify_with_positional_push(self):
class Content(EmbeddedDocument):
keywords = ListField(StringField())
class BlogPost(Document):
tags = ListField(StringField())
content = EmbeddedDocumentField(Content)
post = BlogPost.objects.create(
tags=['python'], content=Content(keywords=['ipsum']))
post = BlogPost.objects.create(tags=['python'])
self.assertEqual(post.tags, ['python'])
post.modify(push__tags__0=['code', 'mongo'])
self.assertEqual(post.tags, ['code', 'mongo', 'python'])
@@ -856,6 +862,16 @@ class InstanceTest(MongoDBTestCase):
['code', 'mongo', 'python']
)
self.assertEqual(post.content.keywords, ['ipsum'])
post.modify(push__content__keywords__0=['lorem'])
self.assertEqual(post.content.keywords, ['lorem', 'ipsum'])
# Assert same order of the list items is maintained in the db
self.assertEqual(
BlogPost._get_collection().find_one({'_id': post.pk})['content']['keywords'],
['lorem', 'ipsum']
)
def test_save(self):
"""Ensure that a document may be saved in the database."""