Refs #28575 -- Removed unnecessary code for model exception pickling.
Setting __qualname__ is sufficient for pickling of DoesNotExist and and MultipleObjectsReturned to work correctly.
This commit is contained in:
parent
f2868f9739
commit
216eda103b
|
@ -44,30 +44,18 @@ class Deferred:
|
||||||
DEFERRED = Deferred()
|
DEFERRED = Deferred()
|
||||||
|
|
||||||
|
|
||||||
def subclass_exception(name, parents, module, attached_to=None):
|
def subclass_exception(name, bases, module, attached_to):
|
||||||
"""
|
"""
|
||||||
Create exception subclass. Used by ModelBase below.
|
Create exception subclass. Used by ModelBase below.
|
||||||
|
|
||||||
If 'attached_to' is supplied, the exception will be created in a way that
|
The exception is created in a way that allows it to be pickled, assuming
|
||||||
allows it to be pickled, assuming the returned exception class will be added
|
that the returned exception class will be added as an attribute to the
|
||||||
as an attribute to the 'attached_to' class.
|
'attached_to' class.
|
||||||
"""
|
"""
|
||||||
class_dict = {'__module__': module}
|
return type(name, bases, {
|
||||||
if attached_to is not None:
|
'__module__': module,
|
||||||
def __reduce__(self):
|
'__qualname__': '%s.%s' % (attached_to.__qualname__, name),
|
||||||
# Exceptions are special - they've got state that isn't
|
})
|
||||||
# in self.__dict__. We assume it is all in self.args.
|
|
||||||
return (unpickle_inner_exception, (attached_to, name), self.args)
|
|
||||||
|
|
||||||
def __setstate__(self, args):
|
|
||||||
self.args = args
|
|
||||||
|
|
||||||
class_dict['__reduce__'] = __reduce__
|
|
||||||
class_dict['__setstate__'] = __setstate__
|
|
||||||
if attached_to:
|
|
||||||
class_dict['__qualname__'] = '%s.%s' % (attached_to.__qualname__, name)
|
|
||||||
|
|
||||||
return type(name, parents, class_dict)
|
|
||||||
|
|
||||||
|
|
||||||
class ModelBase(type):
|
class ModelBase(type):
|
||||||
|
@ -1726,9 +1714,3 @@ def model_unpickle(model_id):
|
||||||
|
|
||||||
|
|
||||||
model_unpickle.__safe_for_unpickle__ = True
|
model_unpickle.__safe_for_unpickle__ = True
|
||||||
|
|
||||||
|
|
||||||
def unpickle_inner_exception(klass, exception_name):
|
|
||||||
# Get the exception class from the class it is attached to:
|
|
||||||
exception = getattr(klass, exception_name)
|
|
||||||
return exception.__new__(exception)
|
|
||||||
|
|
Loading…
Reference in New Issue