Refs #28575 -- Allowed pickling Model.DoesNotExist and MultipleObjectsReturned classes.

This commit is contained in:
Rachel Tobin 2017-10-13 06:16:09 -07:00 committed by Tim Graham
parent a7b5ad8b19
commit 6c92f711ea
3 changed files with 11 additions and 1 deletions

View File

@ -64,6 +64,8 @@ def subclass_exception(name, parents, module, attached_to=None):
class_dict['__reduce__'] = __reduce__ class_dict['__reduce__'] = __reduce__
class_dict['__setstate__'] = __setstate__ 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, parents, class_dict)

View File

@ -350,7 +350,7 @@ class ParallelTestSuite(unittest.TestSuite):
- make tracebacks picklable with tblib, if available - make tracebacks picklable with tblib, if available
Even with tblib, errors may still occur for dynamically created Even with tblib, errors may still occur for dynamically created
exception classes such Model.DoesNotExist which cannot be unpickled. exception classes which cannot be unpickled.
""" """
counter = multiprocessing.Value(ctypes.c_int, 0) counter = multiprocessing.Value(ctypes.c_int, 0)
pool = multiprocessing.Pool( pool = multiprocessing.Pool(

View File

@ -47,6 +47,14 @@ class PickleabilityTestCase(TestCase):
self.assertEqual(original.__class__, unpickled.__class__) self.assertEqual(original.__class__, unpickled.__class__)
self.assertEqual(original.args, unpickled.args) self.assertEqual(original.args, unpickled.args)
def test_doesnotexist_class(self):
klass = Event.DoesNotExist
self.assertIs(pickle.loads(pickle.dumps(klass)), klass)
def test_multipleobjectsreturned_class(self):
klass = Event.MultipleObjectsReturned
self.assertIs(pickle.loads(pickle.dumps(klass)), klass)
def test_manager_pickle(self): def test_manager_pickle(self):
pickle.loads(pickle.dumps(Happening.objects)) pickle.loads(pickle.dumps(Happening.objects))