Skip to content

Commit 4e8da7b

Browse files
cclaussParthS007
authored andcommitted
from pymongo.errors import OperationFailure (fossasia#437)
* from pymongo.errors import OperationFailure Attempt to fix fossasia#435 I am not sure if this is sufficient! Reviews please. Deal gracefully with permissions errors when we try to db.create_index(). * line wrap
1 parent 706fdb7 commit 4e8da7b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/query_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@
1818
import os
1919

2020
from pymongo import DESCENDING, MongoClient
21+
from pymongo.errors import OperationFailure
2122

2223
client = MongoClient(os.environ.get('MONGO_URI', 'mongodb://localhost:27017/'))
2324
db = client['query-server-v2']
2425
db = db['queries'] # Automatically delete records that are older than one day
25-
db.create_index([('createdAt', DESCENDING)], expireAfterSeconds=60 * 60 * 24)
26+
try:
27+
db.create_index([('createdAt', DESCENDING)],
28+
expireAfterSeconds=60 * 60 * 24)
29+
except OperationFailure:
30+
pass # Database index already exists
2631

2732

2833
def lookup(url):

0 commit comments

Comments
 (0)