Skip to content

Commit d433133

Browse files
authored
Merge pull request #39 from gisce/pymongo_versions_compat
Pymongo versions compatibility
2 parents ee9a255 + 948deee commit d433133

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

orm_mongodb.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ def _auto_init(self, cr, context=None):
7171
collection = db[self._table]
7272
#Create index for the id field
7373
try:
74-
collection.ensure_index([('id', pymongo.ASCENDING)],
75-
ttl=300,
76-
unique=True)
74+
# Replace for create_index in a future, ensure_index deprecated since 3.
75+
collection.ensure_index([('id', pymongo.ASCENDING)], cache_for=300, unique=True)
7776
except pymongo.errors.OperationFailure as e:
78-
if e.details and "already exists with different options" in e.details.get("errmsg", " "):
77+
if e.details and "An existing index has the same name as the requested index" in e.details.get("errmsg", " "):
78+
pass
79+
elif e.details and "already exists with different options" in e.details.get("errmsg", " "):
7980
pass
8081
else:
8182
raise
@@ -109,7 +110,7 @@ def _auto_init(self, cr, context=None):
109110
{'$set': def_values},
110111
upsert=False,
111112
manipulate=False,
112-
safe=True,
113+
w=1,
113114
multi=True)
114115

115116
if db.error():
@@ -489,8 +490,7 @@ def search(self, cr, user, args, offset=0, limit=0, order=None,
489490
return collection.find(
490491
new_args,
491492
{'id': 1},
492-
no_cursor_timeout=True,
493-
modifiers={"$snapshot": False},
493+
no_cursor_timeout=True
494494
).count()
495495

496496
mongo_cr = collection.find(
@@ -499,8 +499,8 @@ def search(self, cr, user, args, offset=0, limit=0, order=None,
499499
skip=int(offset),
500500
limit=int(limit),
501501
no_cursor_timeout=True,
502-
modifiers={"$snapshot": False},
503502
sort=self._compute_order(cr, user, order))
503+
# Removed modifiers={"$snapshot": False}, False by default
504504

505505
res = [x['id'] for x in mongo_cr if 'id' in x]
506506

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pymongo==2.9;python_version<="2.7.18"
2-
pymongo>=3.12;python_version>"2.7.18"
1+
pymongo==3.13.0;python_version<="2.7.18"
2+
pymongo>=3.13.0;python_version>"2.7.18"
33
six

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestTranslateDomain(unittest.TestCase):
1515
def test_translate_domain(self):
1616
mdbconn = mongodb2.MDBConn()
1717
res = mdbconn.translate_domain([('name', '=', 'ol')])
18-
self.assertEqual(res, {'name': 'ol'})
18+
self.assertIn(res, ({'name': 'ol'}, {'name': {'$eq': 'ol'}}))
1919

2020
res = mdbconn.translate_domain([('name', '!=', 'ol')])
2121
self.assertEqual(res, {'name': {'$ne': 'ol'}})

0 commit comments

Comments
 (0)