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

Cannot custom _id #85

Open
veerkat opened this issue Feb 27, 2015 · 0 comments
Open

Cannot custom _id #85

veerkat opened this issue Feb 27, 2015 · 0 comments

Comments

@veerkat
Copy link

veerkat commented Feb 27, 2015

I try to custom _id, like this:

User.objects.create(_id=1, name="veerkat")

but it failed.
Because objects.create call QuerySet.create

@return_future
def create(self, callback, alias=None, **kwargs):
    document = self.__klass__(**kwargs)
    self.save(document=document, callback=callback, alias=alias)

def save(self, document, callback, alias=None):
    if self.validate_document(document):
        self.ensure_index(callback=self.indexes_saved_before_save(document, callback, alias=alias), alias=alias)

def indexes_saved_before_save(self, document, callback, alias=None):
    def handle(*args, **kw):
        self.update_field_on_save_values(document, document._id is not None)
        doc = document.to_son()

        if document._id is not None:
            self.coll(alias).update({'_id': document._id}, doc, callback=self.handle_update(document, callback))
        else:
            self.coll(alias).insert(doc, callback=self.handle_save(document, callback))

    return handle

and create method call save method. But in indexes_saved_before_save method, if document._id is not None, it will call update method, and cannot create an new instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant