3436 Commits

Author SHA1 Message Date
Erdenezul Batmunkh
a06e605e67 Add BulkWriteError exception 2019-08-29 11:11:27 +02:00
Erdenezul Batmunkh
e86cf962e9 Change misleading error message 2019-08-21 13:08:30 +02:00
erdenezul
99a58d5c91
Merge pull request #2149 from AliMirlou/patch-1
Fix small typo
2019-08-21 11:04:20 +02:00
Ali Mirlou
eecbb5ca90
Fix small typo 2019-08-20 19:53:49 +04:30
Bastien Gérard
0d01365751
Merge pull request #2131 from NMFR/master
Set default database when using mongomock.
2019-07-22 11:56:56 +02:00
Nuno Rodrigues
f4a06ad65d Optimize database name getter calls 2019-07-22 08:45:35 +00:00
Nuno Rodrigues
05a22d5a54 Extract test to its own method 2019-07-22 08:42:17 +00:00
Nuno Rodrigues
2424ece0c5 Fix a linting error 2019-07-16 13:40:46 +00:00
Nuno Rodrigues
2d02551d0a Add test 2019-07-15 17:54:46 +01:00
Stefan Wójcik
ac416aeeb3
Improve BaseDocument.from_json tests and documentation (#2127) 2019-07-15 12:15:55 +02:00
Stefan Wojcik
d09af430e8 Fix formatting of the changelog – part 2
RTD didn't render it properly previously.

Refs #2105
2019-07-15 09:57:48 +02:00
Stefan Wojcik
79454b5eed Fix formatting of the changelog
RTD didn't render it properly previously.

Refs #2105
2019-07-15 09:54:18 +02:00
Stefan Wojcik
921c1fa412 Dummy commit to confirm that the new RTD webhook works 2019-07-15 09:50:29 +02:00
Stefan Wojcik
1aba145bc6 Split requirements into requirements.txt and requirements-lint.txt
I'm doing this because it makes sense to separate which requirements are
needed to develop the package and which are purely needed for static code
analysis. That said, the trigger for this commit was that ReadTheDocs
automatically tries to install everything that's in requirements.txt and,
since `black` isn't available on Python 2.7, it was failing. See
https://readthedocs.org/projects/mongoengine-odm/builds/9371765/.

Refs #2105
2019-07-15 09:32:26 +02:00
Nuno Rodrigues
290d9df3eb Set default database when using mongomock.
When passing host `mongomock://localhost/some-default-database` to `connect` the default database was `"test"` instead of `"some-default-database"`.

Fixes: #2130
2019-07-12 13:33:19 +01:00
Stefan Wójcik
aa76ccdd25
Fix Document._object_key (#2125)
Previous implementation of `Document._object_key` was *pretending* to work on
MongoEngine-level fields (e.g. using "pk" instead of "_id" and separating
nested field parts by "__" instead of "."), but then it was also attempting to
transform field names from the `shard_key` into DB-level fields.

This, expectedly, didn't really work well. Most of the test cases added in this
commit were failing prior to the code fixes.
2019-07-09 12:08:26 +02:00
Andreas Doll
abe8070c36 Document register_connection arguments in correct order (#2121)
Put the documentation of the parameter 'name' of the function
'register_connection' in order of appearance in the function signature.
2019-07-08 14:16:09 +02:00
Bastien Gérard
2d28c258fd
Merge pull request #2115 from bagerard/use_globals_in_travis_yml
Use global constants for mongo/pymongo in travis.yml
2019-07-03 11:47:35 +02:00
Stefan Wójcik
1338839b52
Update changelog.rst 2019-07-03 11:18:56 +02:00
Stefan Wojcik
058203a0ec More changelog tweaks [ci skip]
The main change is that we're now using double backticks (``), which are the
correct way to format code in an RST file.
2019-07-03 11:12:25 +02:00
Stefan Wojcik
8fdf664968 Changelog tweaks [ci skip] 2019-07-03 11:08:51 +02:00
Stefan Wójcik
50555ec73e
Better management of the automatic "_cls" field (#2112)
* Rename BaseQuerySet._initial_query to BaseQuerySet._cls_query

This new name more accurately reflects the purpose of the dict. It is either
empty for documents that don't use inheritance or it contains a `{"_cls": ...}`
shape query. There was nothing "initial" about it per se.

* Drop read_preference as a kwarg on BaseQuerySet.__call__/filter

It was a poor design choice to offer two different ways to do the same thing:
1. `SomeDoc.objects(foo=bar, bar=baz).read_preference(...)`
2. `SomeDoc.objects(foo=bar, bar=baz, read_preference=...)`

Option 1 is good because it's immediately obvious which part defines the query
to be used and which part defines the read preference.

Option 2 is bad because you don't immediately know whether `read_preference`
is a query kwarg or a reserved keyword with some special behavior. If you
wanted to be particularly cruel, you could even write
`SomeDoc.objects(foo=bar, read_preference=..., bar=baz)`.

THIS IS A BREAKING CHANGE. From now on you have to use the
`BaseQuerySet.read_preference(...)` method.

* Add a BaseQuerySet.clear_cls_query method + get rid of the class_check kwarg

This is similar to what the previous commit did to read preference except that
in this case we were still missing a `BaseQuerySet` method for clearing the
`_cls` query.

Now, instead of the undocumented, untested, and confusing interface:
    `ParentDoc.objects(foo=bar, bar=baz, class_check=False)`
We do:
    `ParentDoc.objects(foo=bar, bar=baz).clear_cls_query()`
2019-07-03 11:07:55 +02:00
Bastien Gérard
951a532a9f additional fix in travis/tox 2019-07-03 09:15:28 +02:00
Bastien Gérard
e940044603 fixes in .travis.yml and tox.ini based on PR review 2019-07-02 23:06:31 +02:00
Bastien Gérard
babfbb0fcd Merge branch 'master' of github.com:MongoEngine/mongoengine into use_globals_in_travis_yml 2019-07-02 22:57:03 +02:00
Stefan Wojcik
bbed312bdd Final changelog tweaks [ci skip] 2019-07-02 18:42:50 +02:00
Stefan Wojcik
b593764ded One more changelog tweak [ci skip] 2019-07-02 18:35:29 +02:00
Stefan Wojcik
483c840fc8 One more changelog tweak [ci skip] 2019-07-02 18:29:28 +02:00
Stefan Wojcik
de80f0ccff Clean up the changelog [ci skip]
Mostly making sure that code is formatted using backticks and that wording and
punctuation are consistent.
2019-07-02 18:28:04 +02:00
Stefan Wójcik
d0b87f7f82
Drop the deprecated "format" param from BaseQuerySet.explain (#2113)
That option was pretty useless. You can very easily do:
```
import pprint
(...)

plan = SomeDoc.objects(...).explain()
pprint.pformat(plan)
```
2019-07-01 10:18:47 +02:00
Bastien Gérard
bf32d3c39a Merge branch 'master' of github.com:MongoEngine/mongoengine into use_globals_in_travis_yml 2019-06-30 21:11:42 +02:00
Bastien Gérard
bc14f2cdaa
Merge pull request #2083 from bagerard/improve_travis_yml2
add pypy3 back to travis and improve python 3.7 integration
2019-06-30 21:11:00 +02:00
Bastien Gérard
06a21e038a Use global constants for mongo/pymongo in travis.yml 2019-06-30 21:04:23 +02:00
Bastien Gérard
4d5eba317e convert travis test on latest python/mongo/pymongo from python 3.6 to 3.7 2019-06-30 20:55:19 +02:00
Stefan Wójcik
9170eea784
Rename MongoEngineConnectionError to ConnectionFailure (#2111)
I originally changed the exception name from `ConnectionError` to
`MongoEngineConnectionError` in
b02904ee75,
inspired by landscape.io's package health report, which argued that
`ConnectionError` is already a built-in exception in Python 3 (which it is:
https://docs.python.org/3/library/exceptions.html#ConnectionError).

I do agree that we shouldn't override built-in exceptions. [0] That said, it’s
silly to add a "MongoEngine" prefix to any class within the `mongoengine`
module (and *especially* to *just one* exception class out of many). I've
decided to do what PyMongo does (
8855a510a8/pymongo/errors.py (L59))
and call this exception `ConnectionFailure`.

Note that this is a breaking change and people will need to rename
`MongoEngineConnectionError`s in their code to `ConnectionFailure`. Moreover,
if they use PyMongo's `ConnectionFailure` for anything, they'll need to take
    extra care to avoid conflicts, e.g. by using:
```
from mongoengine import ConnectionFailure as MongoEngineConnectionFailure
```

[0] Note that some popular packages still overwrite `ConnectionError`, e.g.
4983a9bde3/requests/exceptions.py (L32)
or
0be4d29206/redis/exceptions.py (L8)
2019-06-30 09:23:32 +02:00
Stefan Wojcik
2769967e1e Update the changelog [ci skip] 2019-06-27 17:41:29 +02:00
Stefan Wójcik
609f50d261
Fix the duplicate ListField max_length test (#2110)
This is a follow-up after #2107.

Not sure what happened here, but in
87194856ec
I committed a copy-paste of the same test instead of a test validating the
max_length behavior along with a "set" operator.
2019-06-27 16:45:31 +02:00
Stefan Wójcik
82f0eb1cbc
Add a max_length param to the ListField (#2107)
This is similar to the `max_length` param of a `StringField`.

Sometimes you don't want your lists to be able to grow indefinitely.
2019-06-27 15:07:02 +02:00
Stefan Wójcik
b47669403b
Format the codebase using Black (#2109)
This commit:
1. Formats all of our existing code using `black`.
2. Adds a note about using `black` to `CONTRIBUTING.rst`.
3. Runs `black --check` as part of CI (failing builds that aren't properly formatted).
2019-06-27 13:05:54 +02:00
Stefan Wojcik
91899acfe5 Clarify unack'd write concern not returning the deleted count [ci skip] 2019-06-26 15:14:43 +02:00
Stefan Wójcik
ffedd33101
Drop support for positional arguments when instantiating a document (#2103)
For example, if you had the following class:
```
class Person(Document):
    name = StringField()
    age = IntField()
```

You could instantiate an object of such class by doing one of the following:
1. `new_person = Person('Tom', 30)`
2. `new_person = Person('Tom', age=30)`
3. `new_person = Person(name='Tom', age=30)`

From now on, only option (3) is allowed.

Supporting positional arguments may sound like a reasonable idea in this
heavily simplified example, but in real life it's almost never what you want
(especially if you use inheritance in your document definitions) and it may
lead to ugly bugs. We should not rely on the *order* of fields to match a given
value to a given name.

This also helps us simplify the code e.g. by dropping the confusing (and
undocumented) `BaseDocument._auto_id_field` attribute.
2019-06-26 11:31:11 +02:00
Stefan Wojcik
af292b0ec2 Bump version to v0.18.2 v0.18.2 2019-06-25 16:52:31 +02:00
Stefan Wojcik
1ead7f9b2b Add changelog entries for v0.18.2 2019-06-25 16:51:56 +02:00
Stefan Wojcik
5c91877b69 Fix the Travis deployment condition
See https://github.com/MongoEngine/mongoengine/issues/2104 for details.

For now I'm hardcoding `$MONGODB = 3.4.17` just to get a release out there,
but we should probably use the globals going forward. Will do that in
a follow-up commit once I get the `travis-conditions` gem up and running and
hence can test `.travis.yml` changes without deploying.
2019-06-25 16:48:51 +02:00
Stefan Wojcik
e57d834a0d Fix automated tests for py3 2019-06-25 12:41:59 +02:00
Stefan Wojcik
0578cdb62e Cleaner loop using itertools.count() 2019-06-25 11:41:27 +02:00
Stefan Wojcik
b661afba01 Use set comprehensions for existing_fields & existing_db_fields 2019-06-25 11:34:31 +02:00
Bastien Gérard
b1002dd4f9
Merge pull request #2097 from bagerard/remove_deprecated_pymongo_methods
remove pymongo deprecated methods: find_and_modify & remove
2019-06-24 22:03:58 +02:00
Stefan Wojcik
8e69008699 Fill in the PR # in the changelog [ci skip] 2019-06-24 16:00:21 +02:00
Stefan Wojcik
f45552f8f8 Drop support for positional arguments when instantiating a document
For example, if you had the following class:
```
class Person(Document):
    name = StringField()
    age = IntField()
```

You could instantiate an object of such class by doing one of the following:
1. `new_person = Person('Tom', 30)`
2. `new_person = Person('Tom', age=30)`
3. `new_person = Person(name='Tom', age=30)`

From now on, only option (3) is allowed.

Supporting positional arguments may sound like a reasonable idea in this
heavily simplified example, but in real life it's almost never what you want
(especially if you use inheritance in your document definitions) and it may
lead to ugly bugs. We should not rely on the *order* of fields to match a given
value to a given name.

This also helps us simplify the code e.g. by dropping the confusing (and
undocumented) `BaseDocument._auto_id_field` attribute.
2019-06-24 15:44:35 +02:00