#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.3f676e8219b7b5554948419dec99078b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to