diff --git a/.travis.yml b/.travis.yml index 05746144..9a7f97e7 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 @@ -14,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: @@ -21,6 +25,10 @@ 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 + allow_failures: + - python: "pypy3" fast_finish: true before_install: @@ -36,12 +44,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: 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 ===== 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 ================ 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/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/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): 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()