Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branches #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 8 additions & 1 deletion mongoalchemy/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions mongoalchemy/fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion mongoalchemy/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be protected by an option? Given that we currently don't use a sharded database it seems unfortunate to crash on all queries that don't yet support it

# 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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down