Commit Graph
100 Commits
Author SHA1 Message Date
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ójcikandGitHub 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
Stefan WójcikandGitHub 9170eea784 Rename MongoEngineConnectionError to ConnectionFailure (#2111)
I originally changed the exception name from `ConnectionError` to
`MongoEngineConnectionError` in
https://github.com/MongoEngine/mongoengine/pull/1428/commits/b02904ee750a30f8e2246a326376b40358543101,
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 (
https://github.com/mongodb/mongo-python-driver/blob/8855a510a80a30268ffd4b90be65fb26929648e2/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.
https://github.com/kennethreitz/requests/blob/4983a9bde39c6320aa4f3e34e50dac6e263dab6f/requests/exceptions.py#L32
or
https://github.com/andymccurdy/redis-py/blob/0be4d2920684345eb52115c7142c39d65356e7d4/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ójcikandGitHub 609f50d261 Fix the duplicate ListField max_length test (#2110)
This is a follow-up after #2107.

Not sure what happened here, but in
https://github.com/MongoEngine/mongoengine/pull/2107/commits/87194856ecc5076bec2a186bae60c5d5b25c01ed
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ójcikandGitHub 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ójcikandGitHub 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ójcikandGitHub 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 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
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
Stefan Wojcik a4fe091a51 Cleaner code & comments in BaseField.__set__ 2019-06-21 13:51:53 +02:00
Stefan Wojcik 216217e2c6 Datastructures comments: fix typos and tweak formatting [ci skip] 2019-06-21 13:48:24 +02:00
Stefan Wojcik 799775b3a7 Slightly cleaner docstring of BaseQuerySet.no_sub_classes [ci skip] 2019-06-20 12:18:58 +02:00
Stefan WójcikandGitHub ae0384df29 Improve Document.meta.shard_key docs (#2099)
This closes #2096. Previous documentation of the shard_key meta attribute was
missing the crucial point that it really only matters if your collection is
sharded over a compound index.
2019-06-20 11:25:51 +02:00
Stefan WójcikandGitHub bb0b1e88ef Split up custom PK field tests (#2095)
This more closely aligns with the rule that a single tests should test one
thing and one thing only. Previous code tested like 4 different things in a
single test and was hard to follow.
2019-06-18 15:43:46 +02:00
Stefan Wojcik a4e4e8f440 Tweaks to the QuerySet.order_by docstring 2019-06-17 17:28:41 +02:00
Stefan Wojcik b62ce947a6 Cleaner mongoengine.connection.__all__ 2019-06-17 15:42:15 +02:00
Stefan Wojcik 9538662262 Slightly cleaner connection code 2019-06-17 15:34:11 +02:00
Stefan Wojcik 09d7ae4f80 More BaseDocument.__init__ documentation tweaks 2019-06-17 14:52:26 +02:00
Stefan Wojcik d7ded366c7 Document params expected by BaseDocument.__init__ [ci skip] 2019-06-17 14:37:14 +02:00
Stefan WójcikandGitHub 09c77973a0 Clean up how _changed_fields are set in BaseDocument._from_son (#2090) 2019-06-17 13:41:02 +02:00
Stefan Wojcik 22f3c70234 Fix PyMongo dependency in the readme [ci skip] 2019-06-17 09:41:41 +02:00
Stefan Wojcik 6527b1386f Benchmarks: Python 3 tweaks + more consistent testing of small vs big docs 2019-06-17 09:31:51 +02:00
Stefan Wojcik 1fcd706e11 Clearer docstring of Document._get_collection [ci skip] 2019-06-14 14:57:12 +02:00
Stefan Wojcik 008bb19b0b Add a test covering basic Document operations
It covers operations such as:
1. Document initialization.
2. Accessing/setting attributes on a Document instance.
3. Serializing a Document instance (via `to_mongo`).
4. Deserializing a Document instance (via `_from_son`).
5. Serializing + saving a Document in the database (via `save`).
5. Loading a Document from the database + deserializing (via `Doc.objects[0]`).

And it does so for both basic flat documents and more complex nested docs.
2019-06-14 11:59:41 +02:00
Stefan Wojcik 023acab779 Clean up benchmark.py and move it to benchmarks/test_inserts.py
1. Removes the cascade=save tests. It's not an option I'd recommend using AND
   it primarily matters if you have any reference fields in your document,
   which is not the case in this script.
2. Uses PyMongo-v3.x-style write concern.
3. Removes an old docstring describing some random benchmark run from the past.
4. Removes unused parts of the code.

I'll add more tests to the "benchmarks/" directory in future commits.
2019-06-14 11:59:41 +02:00
Stefan Wojcik aa8a991d20 Try a different deployment condition
This time my attempt is based on the output found in another job that didn't
trigger a deployment: https://travis-ci.org/MongoEngine/mongoengine/jobs/544664203

```
/home/travis/.travis/job_stages: line 660: expected `)'
/home/travis/.travis/job_stages: line 660: syntax error near `AND'
/home/travis/.travis/job_stages: line 660: `  if [[ ($TRAVIS_REPO_SLUG = "MongoEngine/mongoengine") && ($TRAVIS_PYTHON_VERSION = 2.7) && ($PYMONGO = 3.x AND $MONGODB = 3.4) && ("$TRAVIS_TAG" != "") ]]; then'
```

See 80ca6360c1f3ea073e3fcb65070ded0558514ffa and
40ba51ac43 for my previous attempts.
2019-06-12 12:19:36 +02:00
Stefan Wojcik 40ba51ac43 Try a different deployment condition
The previous one was a verbatim copy-paste of what TravisCI's Support suggested
to me, but sadly it didn't work. See
https://travis-ci.org/MongoEngine/mongoengine/jobs/544655132. That build
should've triggered a deployment.

This time I'm trying a different syntax, primarily influenced by
https://docs.travis-ci.com/user/conditions-v1#boolean-operators.
2019-06-12 12:08:11 +02:00
Stefan Wojcik d20430a778 Bump up waiting for MongoDB from 15s to 20s
I've noticed that `mongo --eval 'db.version()'` has been failing fairly
regularly in the last few weeks. Hopefully that extra 5s is enough.
2019-06-12 11:57:25 +02:00
Stefan Wojcik f08f749cd9 Bump version to v0.18.0 2019-06-12 11:47:31 +02:00
Stefan Wojcik a6c04f4f9a Finalize the v0.18.0 changelog [ci skip] 2019-06-12 11:38:58 +02:00
Stefan Wojcik 15b6c1590f Add extra context to the BaseDocument.validate docstring 2019-06-12 11:37:08 +02:00
Stefan Wojcik 996618a495 Fix wording of an exception message in QuerySet.insert 2019-06-12 08:29:59 +02:00
Stefan Wojcik f131b18cbe Make test_update_shard_key_routing more resilient 2019-06-11 15:50:22 +02:00
Stefan Wojcik 118a998138 Classify the QuerySet.aggregate change as a bugfix [ci skip] 2019-06-11 15:09:16 +02:00
Stefan Wojcik 31d99c0bd2 Cleaner wording in the dev changelog 2019-06-10 11:26:47 +02:00
Stefan Wojcik 8e8c74c621 Drop the unused mongodb_version attribute in IndexesTest 2019-06-07 12:35:38 +02:00
Stefan Wojcik f996f3df74 Cleaner test_hint 2019-06-07 12:34:32 +02:00
Stefan Wojcik 9499c97e18 Clean up the .install_mongodb_on_travis.sh script
This is a leftover from #2066. Since we no longer install MongoDB versions
v2.6 – v3.2, we no longer need this code.
2019-06-07 12:16:32 +02:00
Stefan WójcikandGitHub 4334955e39 Update the test matrix to reflect what's supported in 2019 (#2066)
Previously, we were running the test suite for several combinations of MongoDB,
Python, and PyMongo:
- PyPy, MongoDB v2.6, PyMongo v3.x (which really means v3.6.1 at the moment)
- Python v2.7, MongoDB v2.6, PyMongo v3.x
- Python v3.5, MongoDB v2.6, PyMongo v3.x
- Python v3.6, MongoDB v2.6, PyMongo v3.x
- Python v2.7, MongoDB v3.0, PyMongo v3.5.0
- Python v3.6, MongoDB v3.0, PyMongo v3.5.0
- Python v3.5, MongoDB v3.2, PyMongo v3.x
- Python v3.6, MongoDB v3.2, PyMongo v3.x
- Python v3.6, MongoDB v3.4, PyMongo v3.x
- Python v3.6, MongoDB v3.6, PyMongo v3.x

There were a couple issues with this setup:
1. MongoDB v2.6 – v3.2 have reached their End of Life already (v2.6 almost 3
   years ago!). See the "MongoDB Server" section on
   https://www.mongodb.com/support-policy.
2. We were only testing two recent-ish PyMongo versions (v3.5.0 & v3.6.1).
   We were not testing the oldest actively supported MongoDB/PyMongo/Python
   setup.

This PR updates the test matrix so that these problems are solved. For the
sake of simplicity, it does not yet attempt to cover MongoDB v4.0:
- PyPy, MongoDB v3.4, PyMongo v3.x (aka v3.6.1 at the moment)
- Python v2.7, MongoDB v3.4, PyMongo v3.x
- Python v3.5, MongoDB v3.4, PyMongo v3.x
- Python v3.6, MongoDB v3.4, PyMongo v3.x
- Python v2.7, MongoDB v3.4, PyMongo v3.4
- Python v3.6, MongoDB v3.6, PyMongo v3.x
2019-05-31 11:01:15 +02:00
Stefan Wojcik dabe8c1bb7 highlight places where ValidationError is raised outside of validate() method 2018-03-14 14:26:46 -04:00
Stefan Wojcik a1494c4c93 v0.14.3 version bump 2017-10-01 17:31:10 -04:00
Stefan Wojcik d79ab5ffeb remove {nospam} from author_email & maintainer_email (PyPI doesnt validate those anymore) 2017-10-01 17:05:28 -04:00
Stefan Wojcik 01526a7b37 v0.14.1 version bump + updated changelog 2017-10-01 16:32:02 -04:00
Stefan Wojcik 091a02f737 minor .travis.yml comment correction [ci skip] 2017-10-01 16:09:10 -04:00
Stefan WójcikandGitHub 3794b181d5 Support for $position with the $push operator (#1566) 2017-07-31 15:36:35 +02:00
Stefan Wojcik a8d6e59a7a minor tweaks to code quality in _fields_to_dbfields 2017-06-18 17:25:39 -07:00
Stefan Wojcik 0bc7aa52d8 more docs tweaks [ci skip] 2017-05-08 00:14:42 -04:00
Stefan Wojcik e52603b4a7 ver bump to v0.14.0 + changelog/upgrade docs update 2017-05-08 00:12:26 -04:00
Stefan WójcikandGitHub 3b88712402 Cleaner as_pymongo (#1549) 2017-05-08 00:02:42 -04:00
Stefan Wojcik 33e9ef2106 dont test pypy3 temporarily 2017-05-07 21:37:38 -04:00
Stefan Wojcik 689fe4ed9a Revert "use a newer pypy3 (https://github.com/travis-ci/travis-ci/issues/6277)"
This reverts commit 944d1c0a4a.
2017-05-07 21:37:14 -04:00
Stefan Wojcik b82d026f39 Revert "fix tox.ini"
This reverts commit c00914bea2.
2017-05-07 21:37:05 -04:00
Stefan Wojcik 009059def4 revert #1497 2017-05-07 21:29:13 -04:00
Stefan WójcikandGitHub 03ff61d113 better db_field validation (#1547) 2017-05-07 21:11:14 -04:00
Stefan Wojcik c00914bea2 fix tox.ini 2017-05-07 20:32:52 -04:00
Stefan Wojcik 944d1c0a4a use a newer pypy3 (https://github.com/travis-ci/travis-ci/issues/6277) 2017-05-07 19:54:58 -04:00
Stefan Wojcik 2cf23e33e3 Document._get_update_doc helper method 2017-05-07 19:26:10 -04:00
Stefan Wojcik e2a0b42d03 clarify test_get_changed_fields_query_count 2017-04-30 18:29:22 -04:00
Stefan WójcikandGitHub 894e9818ac use an external sphinx rtd theme (#1541)
Externalize Sphinx RTD theme
2017-04-30 15:38:21 -04:00
Stefan WójcikandGitHub de18e256ce clean up the Document._get_collection code (#1540) 2017-04-30 14:35:33 -04:00
Stefan WójcikandGitHub 1a3c70ce1b make EmbeddedDocument not hashable by default (#1528) 2017-04-30 13:30:21 -04:00
Stefan Wojcik 824ec42005 bump version to v0.13.0 and fill in the changelog and the upgrade docs 2017-04-16 14:08:46 -04:00
Stefan WójcikandGitHub 466935e9a3 Unicode support in EmailField (#1527) 2017-04-16 13:58:58 -04:00
Stefan Wojcik b52d3e3a7b added one more item to the v0.12.0 changelog 2017-04-07 10:34:04 -04:00
Stefan Wojcik 888a6da4a5 update the changelog and bump the version to v0.12.0 2017-04-07 10:18:39 -04:00
Stefan Wojcik b78010aa94 remove test_last_field_name_like_operator (it's a dupe of the same test in tests/queryset/transform.py) 2017-03-05 21:24:46 -05:00
Stefan WójcikandGitHub 49035543b9 cleanup BaseQuerySet.__getitem__ (#1502) 2017-03-05 21:17:53 -05:00
Stefan WójcikandGitHub f9ccf635ca Respect db fields in multiple layers of embedded docs (#1501) 2017-03-05 18:20:09 -05:00
Stefan Wojcik e8ea294964 test negative indexes (closes #1119) 2017-03-05 18:12:01 -05:00
Stefan Wojcik 19ef2be88b fix #937 2017-03-05 00:05:33 -05:00
Stefan Wojcik 30e8b8186f clean up document instance tests 2017-03-02 00:25:56 -05:00
Stefan WójcikandGitHub 741643af5f clean up field unit tests (#1498) 2017-03-02 00:05:10 -05:00
Stefan WójcikandGitHub 5f43c032f2 revamp the "connecting" user guide and test more ways of connecting to a replica set (#1490) 2017-02-26 21:29:06 -05:00
Stefan Wojcik 627cf90de0 tutorial tweaks: better copy + use py3-friendly syntax 2017-02-26 20:30:37 -05:00
Stefan WójcikandGitHub e93a95d0cb Test and document controlling the size of the connection pool (#1489) 2017-02-25 14:09:10 -05:00
Stefan WójcikandGitHub 3f31666796 Fix the exception message when validating unicode URLs (#1486) 2017-02-24 16:18:34 -05:00
Stefan Wojcik 3fe8031cf3 fix EmbeddedDocumentListFieldTestCase 2017-02-22 12:44:05 -05:00
Stefan Wojcik ed34c2ca68 update the changelog and upgrade docs 2017-02-09 12:13:56 -08:00
Stefan WójcikandGitHub 3ca2e953fb Fix limit/skip/hint/batch_size chaining (#1476) 2017-02-09 12:02:46 -08:00
Stefan Wojcik f33cd625bf nicer readme 2017-01-17 02:47:45 -05:00
Stefan Wojcik 80530bb13c nicer readme 2017-01-17 02:46:37 -05:00
Stefan WójcikandGitHub affc12df4b Update README.rst 2017-01-17 02:43:29 -05:00
Stefan Wojcik 4eedf00025 nicer readme note about dependencies 2017-01-17 02:42:23 -05:00
Stefan Wojcik 1b6743ee53 add a changelog entry about broken references raising DoesNotExist 2017-01-08 14:50:16 -05:00
Stefan WójcikandGitHub ebd34427c7 Cleaner Document.save (#1458) 2016-12-30 05:43:56 -05:00
Stefan WójcikandGitHub 3d75573889 Validate db_field (#1448) 2016-12-29 12:39:05 -05:00
Stefan WójcikandGitHub c6240ca415 Test connection's write concern (#1456) 2016-12-29 12:37:38 -05:00
Stefan WójcikandGitHub 2ee8984b44 add a $rename operator (#1454) 2016-12-28 23:25:38 -05:00
Stefan Wojcik b7ec587e5b better docstring for BaseDocument.to_json 2016-12-28 22:15:46 -05:00
Stefan Wojcik 47c58bce2b fix "connect" example in the docs 2016-12-28 21:08:18 -05:00
Stefan Wojcik 96e95ac533 minor readme tweaks 2016-12-28 17:18:55 -05:00
Stefan Wojcik b013a065f7 remove readme mention of the irc channel 2016-12-28 11:50:28 -05:00