Removed use of _get_subclasses favouring get_document
_get_subclasses not actually required and causes issues where Base Classes aren't imported but dont actually need to be. Fixes #271
This commit is contained in:
		| @@ -845,21 +845,6 @@ class BaseDocument(object): | ||||
|         """ | ||||
|         return cls._meta.get('collection', None) | ||||
|  | ||||
|     @classmethod | ||||
|     def _get_subclasses(cls): | ||||
|         """Return a dictionary of all subclasses (found recursively). | ||||
|         """ | ||||
|         try: | ||||
|             subclasses = cls.__subclasses__() | ||||
|         except: | ||||
|             subclasses = cls.__subclasses__(cls) | ||||
|  | ||||
|         all_subclasses = {} | ||||
|         for subclass in subclasses: | ||||
|             all_subclasses[subclass._class_name] = subclass | ||||
|             all_subclasses.update(subclass._get_subclasses()) | ||||
|         return all_subclasses | ||||
|  | ||||
|     @classmethod | ||||
|     def _from_son(cls, son): | ||||
|         """Create an instance of a Document (subclass) from a PyMongo SON. | ||||
| @@ -877,16 +862,7 @@ class BaseDocument(object): | ||||
|  | ||||
|         # Return correct subclass for document type | ||||
|         if class_name != cls._class_name: | ||||
|             subclasses = cls._get_subclasses() | ||||
|             if class_name not in subclasses: | ||||
|                 # Type of document is probably more generic than the class | ||||
|                 # that has been queried to return this SON | ||||
|                 raise NotRegistered(""" | ||||
|                         `%s` has not been registered in the document registry. | ||||
|                         Importing the document class automatically registers it, | ||||
|                         has it been imported? | ||||
|                     """.strip() % class_name) | ||||
|             cls = subclasses[class_name] | ||||
|             cls = get_document(class_name) | ||||
|  | ||||
|         changed_fields = [] | ||||
|         for field_name, field in cls._fields.items(): | ||||
|   | ||||
| @@ -162,11 +162,10 @@ class Document(BaseDocument): | ||||
|  | ||||
|         doc = self.to_mongo() | ||||
|  | ||||
|         created = '_id' in doc | ||||
|         creation_mode = force_insert or not created | ||||
|         created = force_insert or '_id' not in doc | ||||
|         try: | ||||
|             collection = self.__class__.objects._collection | ||||
|             if creation_mode: | ||||
|             if created: | ||||
|                 if force_insert: | ||||
|                     object_id = collection.insert(doc, safe=safe, **write_options) | ||||
|                 else: | ||||
| @@ -194,7 +193,7 @@ class Document(BaseDocument): | ||||
|         self[id_field] = self._fields[id_field].to_python(object_id) | ||||
|  | ||||
|         self._changed_fields = [] | ||||
|         signals.post_save.send(self.__class__, document=self, created=creation_mode) | ||||
|         signals.post_save.send(self.__class__, document=self, created=created) | ||||
|  | ||||
|     def cascade_save(self, *args, **kwargs): | ||||
|         """Recursively saves any references / generic references on an object""" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user