From 4b689145c0aa72d3280b8748dc61a00e9d346ec0 Mon Sep 17 00:00:00 2001 From: Utkarsh Upadhyay Date: Thu, 4 Aug 2016 22:26:17 +0200 Subject: [PATCH 1/5] Fix parameter names in documentation. `max_length` -> `max_value` for `IntField`s. --- mongoalchemy/fields/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mongoalchemy/fields/fields.py b/mongoalchemy/fields/fields.py index 921ee5d..e1db642 100644 --- a/mongoalchemy/fields/fields.py +++ b/mongoalchemy/fields/fields.py @@ -133,8 +133,8 @@ def validate_wrap(self, value, *types): class IntField(NumberField): ''' Subclass of :class:`~NumberField` for ``int``''' def __init__(self, **kwargs): - ''' :param max_length: maximum value - :param min_length: minimum value + ''' :param max_value: maximum value + :param min_value: minimum value :param kwargs: arguments for :class:`Field` ''' super(IntField, self).__init__(constructor=int, **kwargs) From e64ef0c87feff385637459707fe6090bd789e116 Mon Sep 17 00:00:00 2001 From: Jeffrey Jenkins Date: Mon, 30 Jan 2017 08:59:54 -0500 Subject: [PATCH 2/5] Shut down project. --- README.rst | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 1290011..19bf999 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,6 @@ -Documentation -====================== - -See: http://mongoalchemy.org/ - -This project is in maintenance mode. I'm accepting pull requests and fixing minor bugs, but you should not expect any significant new features or rearchitecting. I'm not writing any python that uses mongo these days, so I'm not keeping up with all of the most recent changes. - -With the exeption of a few issues the project is in pretty good shape and should be usable for many purposes. The most glaring issue right now is that updates and subdocuments really don't play nice together. - -I'm also happy to give the ability to commit to people who submit a lot of good pull requests. +This project is no longer maintained. Please use something else. +================================================================= +If you're interested in taking over maintenance feel free to contact me and we can discuss. From 874751f6aea6d4ec98dbd28d53a7449c1270a5ab Mon Sep 17 00:00:00 2001 From: Danny Chen Date: Tue, 7 Aug 2018 18:34:15 +1000 Subject: [PATCH 3/5] Change SaveOp to do update with shard_key in the Document --- mongoalchemy/document.py | 9 ++++++++- mongoalchemy/ops.py | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mongoalchemy/document.py b/mongoalchemy/document.py index 0f4c072..b2928fd 100644 --- a/mongoalchemy/document.py +++ b/mongoalchemy/document.py @@ -132,6 +132,13 @@ def __new__(mcs, classname, bases, class_dict): class Document(object): # __metaclass__ = DocumentMeta + shard_key = None + ''' The field to specify the shard key for this collection if it is sharded. + For save operations it will look to see if this is set and use + collection.insert/update instead of collection.save because cosmos DB does + not support collection.save + ''' + mongo_id = ObjectIdField(required=False, db_field='_id', on_update='ignore') ''' Default field for the mongo object ID (``_id`` in the database). This field is automatically set on objects when they are saved into the database. @@ -222,7 +229,7 @@ def __init__(self, retrieved_fields=None, loading_from_db=False, **kwargs): self._values[name] = Value(field, self, from_db=False) else: self._values[name] = Value(field, self, from_db=False) - + # Process any extra fields for k in kwargs: if k not in fields: diff --git a/mongoalchemy/ops.py b/mongoalchemy/ops.py index 4e905a0..9047395 100644 --- a/mongoalchemy/ops.py +++ b/mongoalchemy/ops.py @@ -91,6 +91,7 @@ def __init__(self, trans_id, session, document, safe): self.data = document.wrap() self.type = type(document) self.safe = safe + self.shard_key = document.shard_key # Deal with _id if '_id' not in self.data: self.data['_id'] = ObjectId() @@ -100,7 +101,18 @@ def __init__(self, trans_id, session, document, safe): def execute(self): self.ensure_indexes() kwargs = safe_args(self.safe) - return self.collection.save(self.data, **kwargs) + if self.shard_key: + # to support sharded collections the save operation needs to provide the shard key. + if self.shard_key not in self.data: + raise InvalidUpdateException('Requires shard key {} to save'.format(self.shard_key)) + _filter = { + '_id': self.data['_id'], + self.shard_key: self.data[self.shard_key] + } + kwargs['upsert'] = True + return self.collection.update(_filter, self.data, **kwargs) + else: + return self.collection.save(self.data, **kwargs) class RemoveOp(Operation): def __init__(self, trans_id, session, kind, safe, query): From c67178b9a0316f76dac0961bbc823902092fff8e Mon Sep 17 00:00:00 2001 From: Danny Chen Date: Tue, 7 Aug 2018 19:02:31 +1000 Subject: [PATCH 4/5] Rename shard_key class attribute in Document to __shard_key__ in case it's accidently changed --- mongoalchemy/document.py | 2 +- mongoalchemy/ops.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mongoalchemy/document.py b/mongoalchemy/document.py index b2928fd..06e0571 100644 --- a/mongoalchemy/document.py +++ b/mongoalchemy/document.py @@ -132,7 +132,7 @@ def __new__(mcs, classname, bases, class_dict): class Document(object): # __metaclass__ = DocumentMeta - shard_key = None + __shard_key__ = None ''' The field to specify the shard key for this collection if it is sharded. For save operations it will look to see if this is set and use collection.insert/update instead of collection.save because cosmos DB does diff --git a/mongoalchemy/ops.py b/mongoalchemy/ops.py index 9047395..8991d80 100644 --- a/mongoalchemy/ops.py +++ b/mongoalchemy/ops.py @@ -91,7 +91,7 @@ def __init__(self, trans_id, session, document, safe): self.data = document.wrap() self.type = type(document) self.safe = safe - self.shard_key = document.shard_key + self.shard_key = document.__shard_key__ # Deal with _id if '_id' not in self.data: self.data['_id'] = ObjectId() From 9fe9c5c7c6e2a7487f7860779396730762ebd62f Mon Sep 17 00:00:00 2001 From: Danny Chen Date: Tue, 7 Aug 2018 19:03:32 +1000 Subject: [PATCH 5/5] Update version to 0.22.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a5a7c2b..cdbeeaf 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup -VERSION = '0.22.1' +VERSION = '0.22.2' DESCRIPTION = 'Document-Object Mapper/Toolkit for Mongo Databases' setup(