diff --git a/src/typeclasses/managers.py b/src/typeclasses/managers.py index 42d6f3d26..be830f034 100644 --- a/src/typeclasses/managers.py +++ b/src/typeclasses/managers.py @@ -279,6 +279,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager): class TypeclassManager(TypedObjectManager): + def get(self, **kwargs): """ Overload the standard get. This will limit itself to only diff --git a/src/typeclasses/models.py b/src/typeclasses/models.py index 8e7f3b45d..22046ea9a 100644 --- a/src/typeclasses/models.py +++ b/src/typeclasses/models.py @@ -234,7 +234,7 @@ class AttributeHandler(object): "Initialize handler" self.obj = obj self._objid = obj.id - self._model = to_str(obj.__class__.__name__.lower()) + self._model = to_str(obj.__dbclass__.__name__.lower()) self._cache = None def _recache(self): @@ -1091,6 +1091,7 @@ class TypedObject(SharedMemoryModel): def __init__(self, *args, **kwargs): typeclass_path = kwargs.pop("typeclass", None) super(TypedObject, self).__init__(*args, **kwargs) + self.__dbclass__ = self._meta.proxy_for_model if typeclass_path: self.__class__ = self._import_class(typeclass_path) self.db_typclass_path = typeclass_path @@ -1368,6 +1369,13 @@ class TypedObject(SharedMemoryModel): self._is_deleted = True super(TypedObject, self).delete() + def save(self, *args, **kwargs): + "Block saving non-proxy typeclassed objects" + if not self._meta.proxy: + raise RuntimeError("Don't create instances of %s, " + "use its child typeclasses instead." % self.__class__.__name__) + super(TypedObject, self).save(*args, **kwargs) + # # Memory management # diff --git a/src/utils/idmapper/base.py b/src/utils/idmapper/base.py index cdfd7cb2e..70e4a8187 100755 --- a/src/utils/idmapper/base.py +++ b/src/utils/idmapper/base.py @@ -312,11 +312,6 @@ class SharedMemoryModel(Model): def save(self, *args, **kwargs): "save method tracking process/thread issues" - # don't allow saving base objects - if not self._meta.proxy: - raise RuntimeError("Don't create instances of %s, " - "use its child typeclasses instead." % self.__class__.__name__) - if _IS_SUBPROCESS: # we keep a store of objects modified in subprocesses so # we know to update their caches in the central process