From c1b202c119f017d22afb3c0348c13a48c09c6c1f Mon Sep 17 00:00:00 2001 From: DavidBord Date: Sun, 24 Aug 2014 10:47:59 +0300 Subject: [PATCH] fix-#746: Stop ensure_indexes running on a secondaries unless connection is through mongos --- docs/changelog.rst | 1 + mongoengine/document.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 846c5bbd..a330e5d9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,7 @@ Changelog Changes in 0.9.X - DEV ====================== +- Stop ensure_indexes running on a secondaries unless connection is through mongos #746 - Not overriding default values when loading a subset of fields #399 - Saving document doesn't create new fields in existing collection #620 - Added `Queryset.aggregate` wrapper to aggregation framework #703 diff --git a/mongoengine/document.py b/mongoengine/document.py index a81d23b1..34bbb9f6 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -594,7 +594,9 @@ class Document(BaseDocument): index_cls = cls._meta.get('index_cls', True) collection = cls._get_collection() - if collection.read_preference > 1: + # 746: when connection is via mongos, the read preference is not necessarily an indication that + # this code runs on a secondary + if not collection.is_mongos and collection.read_preference > 1: return # determine if an index which we are creating includes