Skip to content

Commit 54bf64a

Browse files
committed
Merge pull request #214 from knowsis/feature/pymongo_3
Support for pymongo 3
2 parents e015ca5 + 605dfcb commit 54bf64a

File tree

14 files changed

+98
-89
lines changed

14 files changed

+98
-89
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ dist/
1212
.tox
1313

1414
MANIFEST
15+
16+
17+
.env
18+
.idea

.travis.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,28 @@ python:
1212
- 2.7
1313

1414
env:
15-
- DJANGO_VERSION=1.4
16-
- DJANGO_VERSION=1.5
17-
- DJANGO_VERSION=1.6
15+
- DJANGO_VERSION=1.4 PYMONGO_VERSION=2.8.1
16+
- DJANGO_VERSION=1.4 PYMONGO_VERSION=3.0.2
17+
- DJANGO_VERSION=1.5 PYMONGO_VERSION=2.8.1
18+
- DJANGO_VERSION=1.5 PYMONGO_VERSION=3.0.2
19+
- DJANGO_VERSION=1.6 PYMONGO_VERSION=2.8.1
20+
- DJANGO_VERSION=1.6 PYMONGO_VERSION=3.0.2
21+
- DJANGO_VERSION=1.7 PYMONGO_VERSION=2.8.1
22+
- DJANGO_VERSION=1.7 PYMONGO_VERSION=3.0.2
23+
1824

1925
matrix:
2026
allow_failures:
21-
- env: DJANGO_VERSION=1.4
27+
- env: DJANGO_VERSION=1.4 PYMONGO_VERSION=2.8.1
28+
- env: DJANGO_VERSION=1.4 PYMONGO_VERSION=3.0.2
29+
- env: DJANGO_VERSION=1.7 PYMONGO_VERSION=2.8.1
30+
- env: DJANGO_VERSION=1.7 PYMONGO_VERSION=3.0.2
2231

2332
install:
2433
- pip install git+http://github.com/django-nonrel/django@nonrel-$DJANGO_VERSION
2534
- pip install git+http://github.com/django-nonrel/django-dbindexer@master
2635
- pip install git+http://github.com/django-nonrel/djangotoolbox@master
36+
- pip install pymongo==$PYMONGO_VERSION --upgrade
2737
- python setup.py install
2838

2939
script: cd tests && python runtests.py

AUTHORS.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Contributions by
2323
* Brandon Pedersen (https://github.com/bpedman)
2424

2525
(For an up-to-date list of contributors, see
26-
https://github.com/django-mongodb-engine/mongodb-engine/contributors.)
26+
https://github.com/django-nonrel/mongodb-engine/contributors.)

django_mongodb_engine/base.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class DatabaseFeatures(NonrelDatabaseFeatures):
3939
supports_microsecond_precision = False
4040
supports_long_model_names = False
4141

42+
can_rollback_ddl = True
43+
4244

4345
class DatabaseOperations(NonrelDatabaseOperations):
4446
compiler_module = __name__.rsplit('.', 1)[0] + '.compiler'
@@ -60,6 +62,9 @@ def sql_flush(self, style, tables, sequence_list, allow_cascade=False):
6062
drop all `tables`. No SQL in MongoDB, so just clear all tables
6163
here and return an empty list.
6264
"""
65+
66+
67+
6368
for table in tables:
6469
if table.startswith('system.'):
6570
# Do not try to drop system collections.
@@ -246,11 +251,6 @@ def pop(name, default=None):
246251
warnings.warn("slave_okay has been deprecated. "
247252
"Please use read_preference instead.")
248253

249-
if replicaset:
250-
connection_class = MongoReplicaSetClient
251-
else:
252-
connection_class = MongoClient
253-
254254
conn_options = dict(
255255
host=host,
256256
port=int(port),
@@ -259,6 +259,11 @@ def pop(name, default=None):
259259
)
260260
conn_options.update(options)
261261

262+
if replicaset:
263+
connection_class = MongoReplicaSetClient
264+
else:
265+
connection_class = MongoClient
266+
262267
try:
263268
self.connection = connection_class(**conn_options)
264269
self.database = self.connection[db_name]

django_mongodb_engine/compiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_cursor(self):
136136
return []
137137

138138
fields = get_selected_fields(self.query)
139-
cursor = self.collection.find(self.mongo_query, fields=fields)
139+
cursor = self.collection.find(self.mongo_query, fields)
140140
if self.ordering:
141141
cursor.sort(self.ordering)
142142
if self.query.low_mark > 0:

django_mongodb_engine/utils.py

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ def log(self, op, duration, args, kwargs=None):
7070
logger.debug(msg, extra={'duration': duration})
7171

7272
def find(self, *args, **kwargs):
73-
if not 'slave_okay' in kwargs and self.collection.slave_okay:
74-
kwargs['slave_okay'] = True
7573
return DebugCursor(self, self.collection, *args, **kwargs)
7674

7775
def logging_wrapper(method):

docs/source/reference/settings.rst

+15-21
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Settings
33

44
.. TODO fix highlighting
55
6-
Connection Settings
6+
Client Settings
77
-------------------
8-
Additional flags may be passed to :class:`pymongo.Connection` using the
8+
Additional flags may be passed to :class:`pymongo.MongoClient` using the
99
``OPTIONS`` dictionary::
1010

1111
DATABASES = {
@@ -14,27 +14,25 @@ Additional flags may be passed to :class:`pymongo.Connection` using the
1414
'NAME' : 'my_database',
1515
...
1616
'OPTIONS' : {
17-
'slave_okay' : True,
18-
'tz_aware' : True,
19-
'network_timeout' : 42,
17+
'socketTimeoutMS' : 500,
2018
...
2119
}
2220
}
2321
}
2422

2523
All of these settings directly mirror PyMongo settings. In fact, all Django
2624
MongoDB Engine does is lower-casing the names before passing the flags to
27-
:class:`~pymongo.Connection`. For a list of possible options head over to the
28-
`PyMongo documentation on connection options`_.
25+
:class:`~pymongo.MongoClient`. For a list of possible options head over to the
26+
`PyMongo documentation on client options`_.
2927

3028
.. _operations-setting:
3129

32-
Safe Operations (``getLastError``)
33-
----------------------------------
30+
Acknowledged Operations
31+
-----------------------
3432
Use the ``OPERATIONS`` dict to specify extra flags passed to
3533
:meth:`Collection.save <pymongo.collection.Collection.save>`,
3634
:meth:`~pymongo.collection.Collection.update` or
37-
:meth:`~pymongo.collection.Collection.remove` (and thus to ``getLastError``):
35+
:meth:`~pymongo.collection.Collection.remove` (and thus included in the write concern):
3836

3937
.. code-block:: python
4038
@@ -43,21 +41,17 @@ Use the ``OPERATIONS`` dict to specify extra flags passed to
4341
...
4442
}
4543
46-
Since any options to ``getLastError`` imply ``safe=True``,
47-
this configuration passes ``safe=True, w=3`` as keyword arguments to each of
48-
:meth:`~pymongo.collection.Collection.save`,
49-
:meth:`~pymongo.collection.Collection.update` and
50-
:meth:`~pymongo.collection.Collection.remove`.
44+
5145
5246
Get a more fine-grained setup by introducing another layer to this dict:
5347

5448
.. code-block:: python
5549
5650
'OPTIONS' : {
5751
'OPERATIONS' : {
58-
'save' : {'safe' : True},
52+
'save' : {'w' : 3},
5953
'update' : {},
60-
'delete' : {'fsync' : True}
54+
'delete' : {'j' : True}
6155
},
6256
...
6357
}
@@ -69,10 +63,10 @@ Get a more fine-grained setup by introducing another layer to this dict:
6963
"`insert vs. update`" into `save`.
7064

7165

72-
A full list of ``getLastError`` flags may be found in the
73-
`MongoDB documentation <http://www.mongodb.org/display/DOCS/getLastError+Command>`_.
66+
A full list of write concern flags may be found in the
67+
`MongoDB documentation <http://docs.mongodb.org/manual/core/write-concern/>`_.
7468

7569
.. _Similar to Django's built-in backends:
7670
http://docs.djangoproject.com/en/dev/ref/settings/#std:setting-OPTIONS
77-
.. _PyMongo documentation on connection options:
78-
http://api.mongodb.org/python/current/api/pymongo/connection.html
71+
.. _PyMongo documentation on client options:
72+
http://api.mongodb.org/python/current/api/pymongo/mongo_client.html

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pymongo<3.0
1+
2+
pymongo>=2.8
3+
24
https://github.com/django-nonrel/djangotoolbox/tarball/master
35
https://github.com/django-nonrel/django/tarball/nonrel-1.5
46
https://github.com/django-nonrel/django-dbindexer/tarball/master

setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
license='2-clause BSD',
1818
description=DESCRIPTION,
1919
long_description=LONG_DESCRIPTION,
20-
install_requires=['pymongo<3.0', 'djangotoolbox>=1.6.0'],
20+
21+
install_requires=['pymongo>=2.8', 'djangotoolbox>=1.6.0'],
22+
2123
packages=find_packages(exclude=['tests', 'tests.*']),
2224
zip_safe=False,
2325
classifiers=[

tests/contrib/tests.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def test_map_reduce_with_custom_primary_key(self, inline=False):
121121
class RawQueryTests(TestCase):
122122

123123
def setUp(self):
124-
MapReduceModel.objects.all().delete()
125124

126125
for i in xrange(10):
127126
MapReduceModel.objects.create(n=i, m=i * 2)
@@ -158,6 +157,10 @@ def test_raw_update(self):
158157
# TODO: Line breaks.
159158
class FullTextTest(TestCase):
160159

160+
def setUp(self):
161+
Post.objects.all().delete()
162+
163+
161164
def test_simple_fulltext(self):
162165
blog = Post(content="simple, full text.... search? test")
163166
blog.save()

tests/lookup/tests.py

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from operator import attrgetter
33

44
from django.core.exceptions import FieldError
5-
from django.db import connection
65
from django.db.utils import DatabaseError
76
from django.test import TestCase, skipUnlessDBFeature
87

@@ -18,10 +17,6 @@
1817
class LookupTests(TestCase):
1918

2019
def setUp(self):
21-
# Create a few Authors.
22-
Author.objects.all().delete()
23-
Article.objects.all().delete()
24-
Tag.objects.all().delete()
2520

2621
self.au1 = Author(name='Author 1')
2722
self.au1.save()

0 commit comments

Comments
 (0)