From 2f72b23a0d4e50d45e8f02bebdf30d9d42f9f59e Mon Sep 17 00:00:00 2001 From: DavidBord Date: Sat, 9 Aug 2014 14:43:21 +0300 Subject: [PATCH 1/8] fix-#725: queryset delete() should return the number of deleted objects --- mongoengine/queryset/base.py | 9 ++++++--- tests/queryset/queryset.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index 2b5c93d5..ce1af2d5 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -405,6 +405,7 @@ class BaseQuerySet(object): will force an fsync on the primary server. :param _from_doc_delete: True when called from document delete therefore signals will have been triggered so don't loop. + :returns number of deleted documents """ queryset = self.clone() doc = queryset._document @@ -422,9 +423,11 @@ class BaseQuerySet(object): has_delete_signal) and not _from_doc_delete if call_document_delete: + cnt = 0 for doc in queryset: doc.delete(write_concern=write_concern) - return + cnt += 1 + return cnt delete_rules = doc._meta.get('delete_rules') or {} # Check for DENY rules before actually deleting/nullifying any other @@ -455,8 +458,8 @@ class BaseQuerySet(object): write_concern=write_concern, **{'pull_all__%s' % field_name: self}) - queryset._collection.remove( - queryset._query, write_concern=write_concern) + result = queryset._collection.remove(queryset._query, write_concern=write_concern) + return result["n"] def update(self, upsert=False, multi=True, write_concern=None, full_result=False, **update): diff --git a/tests/queryset/queryset.py b/tests/queryset/queryset.py index 0eadd7ed..fc56df7d 100644 --- a/tests/queryset/queryset.py +++ b/tests/queryset/queryset.py @@ -4390,6 +4390,17 @@ class QuerySetTest(unittest.TestCase): {'_id': None, 'avg': 29, 'total': 2} ]) + def test_delete_count(self): + [self.Person(name="User {0}".format(i), age=i * 10).save() for i in xrange(1, 4)] + self.assertEqual(self.Person.objects().delete(), 3) # test ordinary QuerySey delete count + + [self.Person(name="User {0}".format(i), age=i * 10).save() for i in xrange(1, 4)] + + self.assertEqual(self.Person.objects().skip(1).delete(), 2) # test Document delete with existing documents + + self.Person.objects().delete() + self.assertEqual(self.Person.objects().skip(1).delete(), 0) # test Document delete without existing documents + if __name__ == '__main__': unittest.main() From 2bf783b04d3d94202c9ed7be6880bd6b54d29125 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sun, 10 Aug 2014 17:01:18 +0300 Subject: [PATCH 2/8] Added PyPy3 to the build matrix. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 05746144..05b10046 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: - "3.3" - "3.4" - "pypy" + - "pypy3" env: - PYMONGO=dev DJANGO=dev - PYMONGO=dev DJANGO=1.6.5 From 50fb5d83f1db100a00dd79784bbd24fac87b9105 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sun, 10 Aug 2014 18:26:18 +0300 Subject: [PATCH 3/8] Added landscape.io badge. --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index df1d5f39..8bc575ee 100644 --- a/README.rst +++ b/README.rst @@ -11,6 +11,10 @@ MongoEngine .. image:: https://coveralls.io/repos/MongoEngine/mongoengine/badge.png?branch=master :target: https://coveralls.io/r/MongoEngine/mongoengine?branch=master + +.. image:: https://landscape.io/github/MongoEngine/mongoengine/master/landscape.png + :target: https://landscape.io/github/MongoEngine/mongoengine/master + :alt: Code Health About ===== From 436b1ce1769a7a4171528404771233050cb1b074 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Sun, 10 Aug 2014 18:44:30 +0300 Subject: [PATCH 4/8] Added PyMongo 2.7.2 to the build matrix. --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 05b10046..e52ccf3d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ env: - PYMONGO=2.7.1 DJANGO=dev - PYMONGO=2.7.1 DJANGO=1.6.5 - PYMONGO=2.7.1 DJANGO=1.5.8 + - PYMONGO=2.7.2 DJANGO=dev + - PYMONGO=2.7.2 DJANGO=1.6.5 + - PYMONGO=2.7.2 DJANGO=1.5.8 matrix: exclude: @@ -22,6 +25,8 @@ matrix: env: PYMONGO=dev DJANGO=dev - python: "2.6" env: PYMONGO=2.7.1 DJANGO=dev + - python: "2.6" + env: PYMONGO=2.7.2 DJANGO=dev fast_finish: true before_install: From bb7e5f17b5d0653387c0f38c9e2da29aa35dad1c Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Tue, 12 Aug 2014 14:52:39 +0100 Subject: [PATCH 5/8] Update .travis.yml Added coveralls coverage... --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index e52ccf3d..d01516fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,12 +42,17 @@ install: - if [[ $DJANGO == 'dev' ]]; then travis_retry pip install https://www.djangoproject.com/download/1.7c2/tarball/; fi - if [[ $DJANGO != 'dev' ]]; then travis_retry pip install Django==$DJANGO; fi - travis_retry pip install https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.1.tar.gz#md5=1534bb15cf311f07afaa3aacba1c028b + - travis_retry pip install coveralls - travis_retry python setup.py install script: - travis_retry python setup.py test - if [[ $TRAVIS_PYTHON_VERSION == '3.'* ]]; then 2to3 . -w; fi; + - coverage run --source=mongoengine setup.py test + - coverage report -m - python benchmark.py +after_script: + coveralls --verbose notifications: irc: "irc.freenode.org#mongoengine" branches: From 46da918dbe55468db2a7c292ec05479821db7ed1 Mon Sep 17 00:00:00 2001 From: DavidBord Date: Sun, 17 Aug 2014 11:19:18 +0300 Subject: [PATCH 6/8] fix-#733: index_cls is ignored when deciding to set _cls as index prefix --- mongoengine/base/document.py | 3 +++ tests/document/indexes.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/mongoengine/base/document.py b/mongoengine/base/document.py index d082f5c0..cfc5de2a 100644 --- a/mongoengine/base/document.py +++ b/mongoengine/base/document.py @@ -718,6 +718,9 @@ class BaseDocument(object): ALLOW_INHERITANCE) include_cls = (allow_inheritance and not spec.get('sparse', False) and spec.get('cls', True)) + + # 733: don't include cls if index_cls is False unless there is an explicit cls with the index + include_cls = include_cls and (spec.get('cls', False) or cls._meta.get('index_cls', True)) if "cls" in spec: spec.pop('cls') for key in spec['fields']: diff --git a/tests/document/indexes.py b/tests/document/indexes.py index 57ee5990..4103c7ae 100644 --- a/tests/document/indexes.py +++ b/tests/document/indexes.py @@ -175,6 +175,16 @@ class IndexesTest(unittest.TestCase): info = A._get_collection().index_information() self.assertEqual(len(info.keys()), 2) + class B(A): + c = StringField() + d = StringField() + meta = { + 'indexes': [{'fields': ['c']}, {'fields': ['d'], 'cls': True}], + 'allow_inheritance': True + } + self.assertEqual([('c', 1)], B._meta['index_specs'][1]['fields']) + self.assertEqual([('_cls', 1), ('d', 1)], B._meta['index_specs'][2]['fields']) + def test_build_index_spec_is_not_destructive(self): class MyDoc(Document): From 6b7e7dc124e34c56190fa9a1a16101fd9d939456 Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Sun, 17 Aug 2014 22:43:36 -0500 Subject: [PATCH 7/8] Update for add the change that closes issue #733 --- docs/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5be1fd9d..c543c4d8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -46,6 +46,7 @@ Changes in 0.9.X - DEV - Workaround a dateutil bug #608 - Conditional save for atomic-style operations #511 - Allow dynamic dictionary-style field access #559 +- index_cls is ignored when deciding to set _cls as index prefix #733 Changes in 0.8.7 ================ From af6699098f7c3aac4afd983bd68c9af69937db7c Mon Sep 17 00:00:00 2001 From: Yohan Graterol Date: Tue, 19 Aug 2014 10:43:22 -0500 Subject: [PATCH 8/8] Update .travis.yml for allow failures in pypy3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d01516fe..9a7f97e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,8 @@ matrix: env: PYMONGO=2.7.1 DJANGO=dev - python: "2.6" env: PYMONGO=2.7.2 DJANGO=dev + allow_failures: + - python: "pypy3" fast_finish: true before_install: