Fixed a bug in object manager.
This commit is contained in:
parent
2ee9e62336
commit
1be49e7bea
2 changed files with 13 additions and 8 deletions
|
|
@ -17,7 +17,7 @@ they control by simply linking to a new object's user property.
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.typeclasses.models import TypeclassBase
|
from src.typeclasses.models import TypeclassBase
|
||||||
from src.objects.manager import ObjectTypeclassManager
|
from src.objects.manager import ObjectManager
|
||||||
from src.objects.models import ObjectDB
|
from src.objects.models import ObjectDB
|
||||||
from src.commands import cmdset, command
|
from src.commands import cmdset, command
|
||||||
from src.utils.logger import log_depmsg
|
from src.utils.logger import log_depmsg
|
||||||
|
|
@ -40,7 +40,7 @@ class Object(ObjectDB):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
__metaclass__ = TypeclassBase
|
__metaclass__ = TypeclassBase
|
||||||
objects = ObjectTypeclassManager()
|
objects = ObjectManager()
|
||||||
|
|
||||||
# __init__ is only defined here in order to present docstring to API.
|
# __init__ is only defined here in order to present docstring to API.
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -305,28 +305,33 @@ class SharedMemoryModel(Model):
|
||||||
|
|
||||||
# per-instance methods
|
# per-instance methods
|
||||||
|
|
||||||
def set_recache_protection(cls, mode=True):
|
def set_recache_protection(self, mode=True):
|
||||||
"set if this instance should be allowed to be recached."
|
"set if this instance should be allowed to be recached."
|
||||||
cls._idmapper_recache_protection = bool(mode)
|
self._idmapper_recache_protection = bool(mode)
|
||||||
|
|
||||||
def save(cls, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"save method tracking process/thread issues"
|
"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:
|
if _IS_SUBPROCESS:
|
||||||
# we keep a store of objects modified in subprocesses so
|
# we keep a store of objects modified in subprocesses so
|
||||||
# we know to update their caches in the central process
|
# we know to update their caches in the central process
|
||||||
global PROC_MODIFIED_COUNT, PROC_MODIFIED_OBJS
|
global PROC_MODIFIED_COUNT, PROC_MODIFIED_OBJS
|
||||||
PROC_MODIFIED_COUNT += 1
|
PROC_MODIFIED_COUNT += 1
|
||||||
PROC_MODIFIED_OBJS[PROC_MODIFIED_COUNT] = cls
|
PROC_MODIFIED_OBJS[PROC_MODIFIED_COUNT] = self
|
||||||
|
|
||||||
if _IS_MAIN_THREAD:
|
if _IS_MAIN_THREAD:
|
||||||
# in main thread - normal operation
|
# in main thread - normal operation
|
||||||
super(SharedMemoryModel, cls).save(*args, **kwargs)
|
super(SharedMemoryModel, self).save(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
# in another thread; make sure to save in reactor thread
|
# in another thread; make sure to save in reactor thread
|
||||||
def _save_callback(cls, *args, **kwargs):
|
def _save_callback(cls, *args, **kwargs):
|
||||||
super(SharedMemoryModel, cls).save(*args, **kwargs)
|
super(SharedMemoryModel, cls).save(*args, **kwargs)
|
||||||
callFromThread(_save_callback, cls, *args, **kwargs)
|
callFromThread(_save_callback, self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class WeakSharedMemoryModelBase(SharedMemoryModelBase):
|
class WeakSharedMemoryModelBase(SharedMemoryModelBase):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue