Fixed #29543 -- Fixed CPointerBase.__del__() ImportError crash.

This commit is contained in:
Mushtaq Ali 2018-07-06 20:26:14 +05:00 committed by Tim Graham
parent f98e1c01ea
commit 66b6b68923
3 changed files with 10 additions and 1 deletions

View File

@ -602,6 +602,7 @@ answer newbie questions, and generally made Django that much better:
Morten Bagai <m@bagai.com> Morten Bagai <m@bagai.com>
msaelices <msaelices@gmail.com> msaelices <msaelices@gmail.com>
msundstr msundstr
Mushtaq Ali <mushtaak@gmail.com>
Mykola Zamkovoi <nickzam@gmail.com> Mykola Zamkovoi <nickzam@gmail.com>
Nagy Károly <charlie@rendszergazda.com> Nagy Károly <charlie@rendszergazda.com>
Nasimul Haque <nasim.haque@gmail.com> Nasimul Haque <nasim.haque@gmail.com>

View File

@ -34,5 +34,5 @@ class CPointerBase:
if self.destructor and self._ptr: if self.destructor and self._ptr:
try: try:
self.destructor(self.ptr) self.destructor(self.ptr)
except (AttributeError, TypeError): except (AttributeError, ImportError, TypeError):
pass # Some part might already have been garbage collected pass # Some part might already have been garbage collected

View File

@ -64,3 +64,11 @@ class CPointerBaseTests(SimpleTestCase):
fg.ptr = ptr fg.ptr = ptr
del fg del fg
destructor_mock.assert_called_with(ptr) destructor_mock.assert_called_with(ptr)
def test_destructor_catches_importerror(self):
class FakeGeom(CPointerBase):
destructor = mock.Mock(side_effect=ImportError)
fg = FakeGeom()
fg.ptr = fg.ptr_type(1)
del fg