[Django] #29543: Bad __del__ code in GeoDjango

18 views
Skip to first unread message

Django

unread,
Jul 3, 2018, 10:51:12 PM7/3/18
to django-...@googlegroups.com
#29543: Bad __del__ code in GeoDjango
------------------------------------------+------------------------
Reporter: Evandro Myller | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
I think something is wrong when GeoDjango tries to cleanup a pointer
before the program exits.

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.

Django

unread,
Jul 4, 2018, 3:17:04 AM7/4/18
to django-...@googlegroups.com
#29543: Bad __del__ code in GeoDjango
--------------------------------+------------------------------------

Reporter: Evandro Myller | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Claude Paroz):

* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

I think your suggested fix makes sense.

--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:1>

Django

unread,
Jul 4, 2018, 3:47:13 AM7/4/18
to django-...@googlegroups.com
#29543: Bad __del__ code in GeoDjango
--------------------------------+------------------------------------

Reporter: Evandro Myller | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 2.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------

Comment (by Mushtaq Ali):

Evandro Myller are you working on this?

--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:2>

Django

unread,
Jul 4, 2018, 5:24:44 AM7/4/18
to django-...@googlegroups.com
#29543: Bad __del__ code in GeoDjango
--------------------------------+---------------------------------------
Reporter: Evandro Myller | Owner: Mushtaq Ali
Type: Bug | Status: assigned
Component: GIS | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+---------------------------------------
Changes (by Mushtaq Ali):

* 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>

Django

unread,
Jul 4, 2018, 7:54:07 AM7/4/18
to django-...@googlegroups.com
#29543: CPointerBase.__del__() crashes with ImportError

--------------------------------+---------------------------------------
Reporter: Evandro Myller | Owner: Mushtaq Ali
Type: Bug | Status: assigned
Component: GIS | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------
Changes (by Tim Graham):

* easy: 1 => 0
* needs_tests: 0 => 1


Comment:

Can you add a regression test?

--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:4>

Django

unread,
Jul 4, 2018, 10:59:35 AM7/4/18
to django-...@googlegroups.com
#29543: CPointerBase.__del__() crashes with ImportError
--------------------------------+---------------------------------------
Reporter: Evandro Myller | Owner: Mushtaq Ali
Type: Bug | Status: assigned
Component: GIS | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------

Comment (by Mushtaq Ali):

Sure.

--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:5>

Django

unread,
Jul 4, 2018, 11:53:54 AM7/4/18
to django-...@googlegroups.com
#29543: CPointerBase.__del__() crashes with ImportError
--------------------------------+---------------------------------------
Reporter: Evandro Myller | Owner: Mushtaq Ali
Type: Bug | Status: assigned
Component: GIS | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------

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>

Django

unread,
Jul 5, 2018, 9:40:44 AM7/5/18
to django-...@googlegroups.com
#29543: CPointerBase.__del__() crashes with ImportError
--------------------------------+---------------------------------------
Reporter: Evandro Myller | Owner: Mushtaq Ali
Type: Bug | Status: assigned
Component: GIS | Version: 2.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------

Comment (by Mushtaq Ali):

Tim I have added the test.

--
Ticket URL: <https://code.djangoproject.com/ticket/29543#comment:7>

Django

unread,
Jul 6, 2018, 11:26:44 AM7/6/18
to django-...@googlegroups.com
#29543: CPointerBase.__del__() crashes with ImportError
--------------------------------+---------------------------------------
Reporter: Evandro Myller | Owner: Mushtaq Ali
Type: Bug | Status: closed
Component: GIS | Version: 2.0
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages