I noticed this while writing some tests; everything goes just fine if all
tests pass, but I'm getting this whenever pytest exits with a failure:
{{{
============================================== FAILURES
==============================================
_________________________________________TestManagerGetQueryset.test_address
___________________________________________
self = <unit.models.test_address.TestManagerGetQueryset object at
0x7f740aee0828>, address = <Address: ...>
def test_address(self, address):
> raise
E RuntimeError: No active exception to reraise
tests/unit/models/test_address.py:14: RuntimeError
========================================================================================================
1 failed, 1 error in 3.82 seconds
========================================================================================================
Exception ignored in: <bound method CPointerBase.__del__ of <Point object
at 0x7f740afb2b38>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/contrib/gis/ptr.py",
line 36, in __del__
File "/usr/local/lib/python3.6/site-
packages/django/contrib/gis/geos/libgeos.py", line 155, in __call__
File "/usr/local/lib/python3.6/site-
packages/django/utils/functional.py", line 36, in __get__
File "/usr/local/lib/python3.6/site-
packages/django/contrib/gis/geos/libgeos.py", line 159, in func
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method CPointerBase.__del__ of <Polygon
object at 0x7f740afb2808>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/contrib/gis/ptr.py",
line 36, in __del__
File "/usr/local/lib/python3.6/site-
packages/django/contrib/gis/geos/libgeos.py", line 155, in __call__
File "/usr/local/lib/python3.6/site-
packages/django/utils/functional.py", line 36, in __get__
File "/usr/local/lib/python3.6/site-
packages/django/contrib/gis/geos/libgeos.py", line 159, in func
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <bound method CPointerBase.__del__ of <Polygon
object at 0x7f740afb2cd0>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/contrib/gis/ptr.py",
line 36, in __del__
File "/usr/local/lib/python3.6/site-
packages/django/contrib/gis/geos/libgeos.py", line 155, in __call__
File "/usr/local/lib/python3.6/site-
packages/django/utils/functional.py", line 36, in __get__
File "/usr/local/lib/python3.6/site-
packages/django/contrib/gis/geos/libgeos.py", line 159, in func
ImportError: sys.meta_path is None, Python is likely shutting down
}}}
This is how I'm able to patch it:
{{{#!python
import pytest
from django.contrib.gis.ptr import CPointerBase
@pytest.fixture(autouse=True, scope="session")
def bad_del_fix():
"""
Fix a bad __del__ happening at GeoDjango
"""
original_del = CPointerBase.__del__
def patched_del(self):
try:
original_del(self)
except ImportError:
pass
CPointerBase.__del__ = patched_del
}}}
I'm not really sure if the fix is just add `ImportError` to the exception
list it expects for at
https://github.com/django/django/blob/2.0/django/contrib/gis/ptr.py#L37.
--
Ticket URL: <https://code.djangoproject.com/ticket/29543>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
I think your suggested fix makes sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:1>
Comment (by Mushtaq Ali):
Evandro Myller are you working on this?
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:2>
* owner: nobody => Mushtaq Ali
* status: new => assigned
* has_patch: 0 => 1
Comment:
I have submitted the fix here https://github.com/django/django/pull/10130
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:3>
* easy: 1 => 0
* needs_tests: 0 => 1
Comment:
Can you add a regression test?
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:4>
Comment (by Mushtaq Ali):
Sure.
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:5>
Comment (by Evandro Myller):
Replying to [comment:1 Claude Paroz]:
> I think your suggested fix makes sense.
I was hoping there was something else to fix the underlying issue, but
that works for me.
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:6>
Comment (by Mushtaq Ali):
Tim I have added the test.
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"66b6b689239dad3f017d2a3495df748cbee5debb" 66b6b689]:
{{{
#!CommitTicketReference repository=""
revision="66b6b689239dad3f017d2a3495df748cbee5debb"
Fixed #29543 -- Fixed CPointerBase.__del__() ImportError crash.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:8>