summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2017-10-13 10:29:34 -0400
committerTim Graham <timograham@gmail.com>2017-10-13 15:45:12 -0400
commit216eda103bee71725b26421e578705f24e17dae0 (patch)
tree020b7b1e6298ec4f6b8145de8831fab0cecbb7ca
parentf2868f97399955650c47c948dc57c376bebb67b1 (diff)
Refs #28575 -- Removed unnecessary code for model exception pickling.
Setting __qualname__ is sufficient for pickling of DoesNotExist and and MultipleObjectsReturned to work correctly.
-rw-r--r--django/db/models/base.py34
1 files changed, 8 insertions, 26 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 1349b1d417..5db600764a 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -44,30 +44,18 @@ class 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.
- If 'attached_to' is supplied, the exception will be created in a way that
- allows it to be pickled, assuming the returned exception class will be added
- as an attribute to the 'attached_to' class.
+ The exception is created in a way that allows it to be pickled, assuming
+ that the returned exception class will be added as an attribute to the
+ 'attached_to' class.
"""
- class_dict = {'__module__': module}
- if attached_to is not None:
- def __reduce__(self):
- # 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)
+ return type(name, bases, {
+ '__module__': module,
+ '__qualname__': '%s.%s' % (attached_to.__qualname__, name),
+ })
class ModelBase(type):
@@ -1726,9 +1714,3 @@ def model_unpickle(model_id):
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)