Skip to content

Commit 758971e

Browse files
author
erdenezul
authored
Merge pull request #1799 from erdenezul/ensure_indexes_fails_on_slave
Ensure indexes fails on slave #1338
2 parents 3654591 + 8739ab9 commit 758971e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dev
1414
- Use new update_one, update_many on document/queryset update #1491
1515
- Use insert_one, insert_many in Document.insert #1491
1616
- Fix reload(fields) affect changed fields #1371
17+
- Fix Read-only access to database fails when trying to create indexes #1338
1718

1819
Changes in 0.15.0
1920
=================

mongoengine/document.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ def _get_collection(cls):
195195

196196
# Ensure indexes on the collection unless auto_create_index was
197197
# set to False.
198-
if cls._meta.get('auto_create_index', True):
198+
# Also there is no need to ensure indexes on slave.
199+
db = cls._get_db()
200+
if cls._meta.get('auto_create_index', True) and\
201+
db.client.is_primary:
199202
cls.ensure_indexes()
200203

201204
return cls._collection

0 commit comments

Comments
 (0)