Skip to content

Commit 3caf2dc

Browse files
author
Erdenezul Batmunkh
committed
Merge branch 'master' into remove_save_embedded
2 parents 9d53ad5 + 1fc5b95 commit 3caf2dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+6040
-4484
lines changed

.install_mongodb_on_travis.sh

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
sudo apt-get remove mongodb-org-server
44
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
55

6-
if [ "$MONGODB" = "2.6" ]; then
7-
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee /etc/apt/sources.list.d/mongodb.list
6+
if [ "$MONGODB" = "3.4" ]; then
7+
sudo apt-key adv --keyserver keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
8+
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
89
sudo apt-get update
9-
sudo apt-get install mongodb-org-server=2.6.12
10+
sudo apt-get install mongodb-org-server=3.4.17
1011
# service should be started automatically
11-
elif [ "$MONGODB" = "3.0" ]; then
12-
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
12+
elif [ "$MONGODB" = "3.6" ]; then
13+
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
14+
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
1315
sudo apt-get update
14-
sudo apt-get install mongodb-org-server=3.0.14
15-
# service should be started automatically
16-
elif [ "$MONGODB" = "3.2" ]; then
17-
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv EA312927
18-
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
19-
sudo apt-get update
20-
sudo apt-get install mongodb-org-server=3.2.20
16+
sudo apt-get install mongodb-org-server=3.6.12
2117
# service should be started automatically
2218
else
23-
echo "Invalid MongoDB version, expected 2.6, 3.0, or 3.2"
19+
echo "Invalid MongoDB version, expected 2.6, 3.0, 3.2, 3.4 or 3.6."
2420
exit 1
2521
fi;
2622

.travis.yml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
# PyMongo combinations. However, that would result in an overly long build
33
# with a very large number of jobs, hence we only test a subset of all the
44
# combinations:
5-
# * MongoDB v2.6 is currently the "main" version tested against Python v2.7,
6-
# v3.5, v3.6, PyPy, and PyMongo v3.x.
7-
# * MongoDB v3.0 & v3.2 are tested against Python v2.7, v3.5 & v3.6
8-
# and Pymongo v3.5 & v3.x
5+
# * MongoDB v3.4 & the latest PyMongo v3.x is currently the "main" setup,
6+
# tested against Python v2.7, v3.5, v3.6, and PyPy.
7+
# * Besides that, we test the lowest actively supported Python/MongoDB/PyMongo
8+
# combination: MongoDB v3.4, PyMongo v3.4, Python v2.7.
9+
# * MongoDB v3.6 is tested against Python v3.6, and PyMongo v3.6, v3.7, v3.8.
10+
#
11+
# We should periodically check MongoDB Server versions supported by MongoDB
12+
# Inc., add newly released versions to the test matrix, and remove versions
13+
# which have reached their End of Life. See:
14+
# 1. https://www.mongodb.com/support-policy.
15+
# 2. https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#python-driver-compatibility
16+
#
917
# Reminder: Update README.rst if you change MongoDB versions we test.
1018

1119
language: python
@@ -17,25 +25,17 @@ python:
1725
- pypy
1826

1927
env:
20-
- MONGODB=2.6 PYMONGO=3.x
28+
- MONGODB=3.4 PYMONGO=3.x
2129

2230
matrix:
2331
# Finish the build as soon as one job fails
2432
fast_finish: true
2533

2634
include:
2735
- python: 2.7
28-
env: MONGODB=3.0 PYMONGO=3.5
29-
- python: 2.7
30-
env: MONGODB=3.2 PYMONGO=3.x
31-
- python: 3.5
32-
env: MONGODB=3.0 PYMONGO=3.5
33-
- python: 3.5
34-
env: MONGODB=3.2 PYMONGO=3.x
35-
- python: 3.6
36-
env: MONGODB=3.0 PYMONGO=3.5
36+
env: MONGODB=3.4 PYMONGO=3.4.x
3737
- python: 3.6
38-
env: MONGODB=3.2 PYMONGO=3.x
38+
env: MONGODB=3.6 PYMONGO=3.x
3939

4040
before_install:
4141
- bash .install_mongodb_on_travis.sh
@@ -49,8 +49,8 @@ install:
4949
- travis_retry pip install --upgrade pip
5050
- travis_retry pip install coveralls
5151
- travis_retry pip install flake8 flake8-import-order
52-
- travis_retry pip install tox>=1.9
53-
- travis_retry pip install "virtualenv<14.0.0" # virtualenv>=14.0.0 has dropped Python 3.2 support (and pypy3 is based on py32)
52+
- travis_retry pip install "tox" # tox 3.11.0 has requirement virtualenv>=14.0.0
53+
- travis_retry pip install "virtualenv" # virtualenv>=14.0.0 has dropped Python 3.2 support (and pypy3 is based on py32)
5454
- travis_retry tox -e $(echo py$TRAVIS_PYTHON_VERSION-mg$PYMONGO | tr -d . | sed -e 's/pypypy/pypy/') -- -e test
5555

5656
# Cache dependencies installed via pip
@@ -85,15 +85,15 @@ deploy:
8585
password:
8686
secure: QMyatmWBnC6ZN3XLW2+fTBDU4LQcp1m/LjR2/0uamyeUzWKdlOoh/Wx5elOgLwt/8N9ppdPeG83ose1jOz69l5G0MUMjv8n/RIcMFSpCT59tGYqn3kh55b0cIZXFT9ar+5cxlif6a5rS72IHm5li7QQyxexJIII6Uxp0kpvUmek=
8787

88-
# create a source distribution and a pure python wheel for faster installs
88+
# Create a source distribution and a pure python wheel for faster installs.
8989
distributions: "sdist bdist_wheel"
9090

91-
# only deploy on tagged commits (aka GitHub releases) and only for the
92-
# parent repo's builds running Python 2.7 along with PyMongo v3.x (we run
93-
# Travis against many different Python and PyMongo versions and we don't
94-
# want the deploy to occur multiple times).
91+
# Only deploy on tagged commits (aka GitHub releases) and only for the parent
92+
# repo's builds running Python v2.7 along with PyMongo v3.x and MongoDB v3.4.
93+
# We run Travis against many different Python, PyMongo, and MongoDB versions
94+
# and we don't want the deploy to occur multiple times).
9595
on:
9696
tags: true
9797
repo: MongoEngine/mongoengine
98-
condition: "$PYMONGO = 3.x"
98+
condition: ($PYMONGO = 3.x) AND ($MONGODB = 3.4)
9999
python: 2.7

AUTHORS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,7 @@ that much better:
248248
* Andy Yankovsky (https://github.com/werat)
249249
* Bastien Gérard (https://github.com/bagerard)
250250
* Trevor Hall (https://github.com/tjhall13)
251-
* Gleb Voropaev (https://github.com/buggyspace)
251+
* Gleb Voropaev (https://github.com/buggyspace)
252+
* Paulo Amaral (https://github.com/pauloAmaral)
253+
* Gaurav Dadhania (https://github.com/GVRV)
254+
* Yurii Andrieiev (https://github.com/yandrieiev)

README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ an `API reference <https://mongoengine-odm.readthedocs.io/apireference.html>`_.
2626

2727
Supported MongoDB Versions
2828
==========================
29-
MongoEngine is currently tested against MongoDB v2.6, v3.0 and v3.2. Future
30-
versions should be supported as well, but aren't actively tested at the moment.
31-
Make sure to open an issue or submit a pull request if you experience any
32-
problems with MongoDB v3.4+.
29+
MongoEngine is currently tested against MongoDB v3.4 and v3.6. Future versions
30+
should be supported as well, but aren't actively tested at the moment. Make
31+
sure to open an issue or submit a pull request if you experience any problems
32+
with MongoDB version > 3.6.
3333

3434
Installation
3535
============
3636
We recommend the use of `virtualenv <https://virtualenv.pypa.io/>`_ and of
3737
`pip <https://pip.pypa.io/>`_. You can then use ``pip install -U mongoengine``.
3838
You may also have `setuptools <http://peak.telecommunity.com/DevCenter/setuptools>`_
39-
and thus you can use ``easy_install -U mongoengine``. Another option is
39+
and thus you can use ``easy_install -U mongoengine``. Another option is
4040
`pipenv <https://docs.pipenv.org/>`_. You can then use ``pipenv install mongoengine``
4141
to both create the virtual environment and install the package. Otherwise, you can
4242
download the source from `GitHub <http://github.com/MongoEngine/mongoengine>`_ and
@@ -47,7 +47,7 @@ Dependencies
4747
All of the dependencies can easily be installed via `pip <https://pip.pypa.io/>`_.
4848
At the very least, you'll need these two packages to use MongoEngine:
4949

50-
- pymongo>=2.7.1
50+
- pymongo>=3.5
5151
- six>=1.10.0
5252

5353
If you utilize a ``DateTimeField``, you might also use a more flexible date parser:

docs/changelog.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,37 @@ Changelog
44

55
Development
66
===========
7+
- Drop support for EOL'd MongoDB v2.6, v3.0, and v3.2.
8+
- MongoEngine now requires PyMongo >= v3.4. Travis CI now tests against MongoDB v3.4 – v3.6 and PyMongo v3.4 – v3.6 (#2017 #2066).
9+
- Improve performance by avoiding a call to `to_mongo` in `Document.save()` #2049
10+
- Connection/disconnection improvements:
11+
- Expose `mongoengine.connection.disconnect` and `mongoengine.connection.disconnect_all`
12+
- Fix disconnecting #566 #1599 #605 #607 #1213 #565
13+
- Improve documentation of `connect`/`disconnect`
14+
- Fix issue when using multiple connections to the same mongo with different credentials #2047
15+
- `connect` fails immediately when db name contains invalid characters #2031 #1718
16+
- Fix the default write concern of `Document.save` that was overwriting the connection write concern #568
17+
- Fix querying on `List(EmbeddedDocument)` subclasses fields #1961 #1492
18+
- Fix querying on `(Generic)EmbeddedDocument` subclasses fields #475
19+
- Generate unique indices for `SortedListField` and `EmbeddedDocumentListFields` #2020
20+
- BREAKING CHANGE: Changed the behavior of a custom field validator (i.e `validation` parameter of a `Field`). It is now expected to raise a `ValidationError` instead of returning True/False #2050
21+
- BREAKING CHANGE: `QuerySet.aggregate` now takes limit and skip value into account #2029
22+
- BREAKING CHANGES (associated with connect/disconnect fixes):
23+
- Calling `connect` 2 times with the same alias and different parameter will raise an error (should call `disconnect` first).
24+
- `disconnect` now clears `mongoengine.connection._connection_settings`.
25+
- `disconnect` now clears the cached attribute `Document._collection`.
726
- (Fill this out as you fix issues and develop your features).
27+
28+
Changes in 0.17.0
29+
=================
830
- Fix .only() working improperly after using .count() of the same instance of QuerySet
31+
- Fix batch_size that was not copied when cloning a queryset object #2011
932
- POTENTIAL BREAKING CHANGE: All result fields are now passed, including internal fields (_cls, _id) when using `QuerySet.as_pymongo` #1976
33+
- Document a BREAKING CHANGE introduced in 0.15.3 and not reported at that time (#1995)
1034
- Fix InvalidStringData error when using modify on a BinaryField #1127
1135
- DEPRECATION: `EmbeddedDocument.save` & `.reload` are marked as deprecated and will be removed in a next version of mongoengine #1552
36+
- Fix test suite and CI to support MongoDB 3.4 #1445
37+
- Fix reference fields querying the database on each access if value contains orphan DBRefs
1238

1339
=================
1440
Changes in 0.16.3
@@ -66,6 +92,7 @@ Changes in 0.16.0
6692

6793
Changes in 0.15.3
6894
=================
95+
- BREAKING CHANGES: `Queryset.update/update_one` methods now returns an UpdateResult when `full_result=True` is provided and no longer a dict (relates to #1491)
6996
- Subfield resolve error in generic_emdedded_document query #1651 #1652
7097
- use each modifier only with $position #1673 #1675
7198
- Improve LazyReferenceField and GenericLazyReferenceField with nested fields #1704

docs/guide/connecting.rst

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
Connecting to MongoDB
55
=====================
66

7-
To connect to a running instance of :program:`mongod`, use the
8-
:func:`~mongoengine.connect` function. The first argument is the name of the
9-
database to connect to::
7+
Connections in MongoEngine are registered globally and are identified with aliases.
8+
If no `alias` is provided during the connection, it will use "default" as alias.
9+
10+
To connect to a running instance of :program:`mongod`, use the :func:`~mongoengine.connect`
11+
function. The first argument is the name of the database to connect to::
1012

1113
from mongoengine import connect
1214
connect('project1')
@@ -42,6 +44,9 @@ the :attr:`host` to
4244
will establish connection to ``production`` database using
4345
``admin`` username and ``qwerty`` password.
4446

47+
.. note:: Calling :func:`~mongoengine.connect` without argument will establish
48+
a connection to the "test" database by default
49+
4550
Replica Sets
4651
============
4752

@@ -71,27 +76,60 @@ is used.
7176
In the background this uses :func:`~mongoengine.register_connection` to
7277
store the data and you can register all aliases up front if required.
7378

74-
Individual documents can also support multiple databases by providing a
79+
Documents defined in different database
80+
---------------------------------------
81+
Individual documents can be attached to different databases by providing a
7582
`db_alias` in their meta data. This allows :class:`~pymongo.dbref.DBRef`
7683
objects to point across databases and collections. Below is an example schema,
7784
using 3 different databases to store data::
7885

86+
connect(alias='user-db-alias', db='user-db')
87+
connect(alias='book-db-alias', db='book-db')
88+
connect(alias='users-books-db-alias', db='users-books-db')
89+
7990
class User(Document):
8091
name = StringField()
8192

82-
meta = {'db_alias': 'user-db'}
93+
meta = {'db_alias': 'user-db-alias'}
8394

8495
class Book(Document):
8596
name = StringField()
8697

87-
meta = {'db_alias': 'book-db'}
98+
meta = {'db_alias': 'book-db-alias'}
8899

89100
class AuthorBooks(Document):
90101
author = ReferenceField(User)
91102
book = ReferenceField(Book)
92103

93-
meta = {'db_alias': 'users-books-db'}
104+
meta = {'db_alias': 'users-books-db-alias'}
105+
106+
107+
Disconnecting an existing connection
108+
------------------------------------
109+
The function :func:`~mongoengine.disconnect` can be used to
110+
disconnect a particular connection. This can be used to change a
111+
connection globally::
112+
113+
from mongoengine import connect, disconnect
114+
connect('a_db', alias='db1')
115+
116+
class User(Document):
117+
name = StringField()
118+
meta = {'db_alias': 'db1'}
119+
120+
disconnect(alias='db1')
121+
122+
connect('another_db', alias='db1')
123+
124+
.. note:: Calling :func:`~mongoengine.disconnect` without argument
125+
will disconnect the "default" connection
126+
127+
.. note:: Since connections gets registered globally, it is important
128+
to use the `disconnect` function from MongoEngine and not the
129+
`disconnect()` method of an existing connection (pymongo.MongoClient)
94130

131+
.. note:: :class:`~mongoengine.Document` are caching the pymongo collection.
132+
using `disconnect` ensures that it gets cleaned as well
95133

96134
Context Managers
97135
================
@@ -119,7 +157,7 @@ access to the same User document across databases::
119157

120158
Switch Collection
121159
-----------------
122-
The :class:`~mongoengine.context_managers.switch_collection` context manager
160+
The :func:`~mongoengine.context_managers.switch_collection` context manager
123161
allows you to change the collection for a given class allowing quick and easy
124162
access to the same Group document across collection::
125163

docs/guide/defining-documents.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ arguments can be set on all fields:
176176
class Shirt(Document):
177177
size = StringField(max_length=3, choices=SIZE)
178178

179+
:attr:`validation` (Optional)
180+
A callable to validate the value of the field.
181+
The callable takes the value as parameter and should raise a ValidationError
182+
if validation fails
183+
184+
e.g ::
185+
186+
def _not_empty(val):
187+
if not val:
188+
raise ValidationError('value can not be empty')
189+
190+
class Person(Document):
191+
name = StringField(validation=_not_empty)
192+
193+
179194
:attr:`**kwargs` (Optional)
180195
You can supply additional metadata as arbitrary additional keyword
181196
arguments. You can not override existing attributes, however. Common

docs/guide/mongomock.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,30 @@ or with an alias:
1919
2020
connect('mongoenginetest', host='mongomock://localhost', alias='testdb')
2121
conn = get_connection('testdb')
22+
23+
Example of test file:
24+
--------
25+
.. code-block:: python
26+
27+
import unittest
28+
from mongoengine import connect, disconnect
29+
30+
class Person(Document):
31+
name = StringField()
32+
33+
class TestPerson(unittest.TestCase):
34+
35+
@classmethod
36+
def setUpClass(cls):
37+
connect('mongoenginetest', host='mongomock://localhost')
38+
39+
@classmethod
40+
def tearDownClass(cls):
41+
disconnect()
42+
43+
def test_thing(self):
44+
pers = Person(name='John')
45+
pers.save()
46+
47+
fresh_pers = Person.objects().first()
48+
self.assertEqual(fresh_pers.name, 'John')

docs/guide/querying.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Available operators are as follows:
6464
* ``gt`` -- greater than
6565
* ``gte`` -- greater than or equal to
6666
* ``not`` -- negate a standard check, may be used before other operators (e.g.
67-
``Q(age__not__mod=5)``)
67+
``Q(age__not__mod=(5, 0))``)
6868
* ``in`` -- value is in list (a list of values should be provided)
6969
* ``nin`` -- value is not in list (a list of values should be provided)
7070
* ``mod`` -- ``value % x == y``, where ``x`` and ``y`` are two provided values

mongoengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
list(signals.__all__) + list(errors.__all__))
2424

2525

26-
VERSION = (0, 16, 3)
26+
VERSION = (0, 17, 0)
2727

2828

2929
def get_version():

0 commit comments

Comments
 (0)