def validate(self, auto_migrate=False):
        if self.use_autorefs:
            if not auto_migrate:
                # don't make reference if auto_migrate is True because this
                # mean validate was called from __init__ and no collection is
                # found when validating at __init__ with autorefs
                self._make_reference(self, self.structure)
        size = self.get_size()
        (size_limit, size_limit_str) = self._get_size_limit()

        if size > size_limit:
            raise MaxDocumentSizeError("The document size is too big, documents "
                                       "lower than %s is allowed (got %s bytes)" % (size_limit_str, size))
        if auto_migrate:
            error = None
            try:
                super(Document, self).validate()
            except StructureError, e:
                error = e
            except __HOLE__, e:
                error = e
            except SchemaTypeError, e:
                error = e
            if error:
                if not self.migration_handler:
                    raise StructureError(str(error))
                else:
                    # if we are here that's becose super.validate failed
                    # but it has processed custom type to bson.
                    self._migrate(process_to_bson=False)
        else:
            super(Document, self).validate()
dataset/ETHPy150Open namlook/mongokit/mongokit/document.py/Document.validate