mod_wsgi: failing isinstance checks on mod_wsgi 4.5.3/Apache 2.4/Windows
Fair warning - we’ve been hitting the wall on this issue for a couple of months now and trying to pin the problem.
Technical stack
- Windows Server
- Apache 2.4
- Python 2.7.12 64 bit (msi installer)
- mod_wsgi-py27-VC9.so, version 4.5.3
- Django 1.9
- third party packages installed:
# # This file is autogenerated by pip-compile # To update, run: # # pip-compile --output-file requirements/base.txt requirements/base.in # -e git+https://redacted/pdf2xml_project.git@1.7.7#egg=pdf2xml abbyy==0.3 amqp==2.1.4 # via kombu backports.functools-lru-cache==1.3 billiard==3.5.0.2 # via celery celery==4.0.2 chardet==3.0.2 # via pdfquery click==6.7 # via pip-tools, python-dotenv contextlib2==0.5.4 # via raven cssselect==1.0.1 # via pdfquery, pyquery diff-match-patch==20121119 # via django-import-export django-choices==1.4.4 django-extra-fields==0.8.0 django-extra-views==0.8.0 django-import-export==0.5.0 django-redis==4.7.0 django-sniplates==0.5.0 django==1.10.7 djangorestframework==3.3.3 first==2.0.1 # via pip-tools kombu==4.0.2 # via celery langdetect==1.0.6 lxml==3.7.3 # via abbyy, pdfquery, pyquery pdfminer==20140328 pdfquery==0.4.3 pillow==3.4.2 pip-tools==1.9.0 psycopg2==2.6.2 pypdf2==1.26.0 pyquery==1.2.17 # via pdfquery python-dotenv==0.6.1 python-levenshtein==0.12.0 pytz==2017.2 # via celery qrcode==5.3 raven==5.32.0 redis==2.10.5 requests==2.13.0 # via abbyy roman==2.0.0 # via pdfquery six==1.10.0 # via django-choices, django-extra-views, langdetect, pdfquery, pip-tools, qrcode tablib==0.11.4 unipath==1.1 vine==1.1.3 # via amqp
Linux
The same app (same versions of python libs and app) is also deployed on Linux boxes, were we haven’t observed this problem.
Problem description
We’re making use of django’s UUIDField
, which does typecasting to handle strings/uuid.UUID
objects and send the right type to the database driver depending on if the backend has native support for uuid or not.
We’ve been hitting odd AttributeError
s on Django’s attempt to cast after a ‘lying’ isinstance check.
The relevant Django code is (in django.db.fields.UUIDField
):
def get_db_prep_value(self, value, connection, prepared=False):
if value is None:
return None
if not isinstance(value, uuid.UUID):
try:
value = uuid.UUID(value)
except AttributeError:
raise TypeError(self.error_messages['invalid'] % {'value': value})
if connection.features.has_native_uuid_field:
return value
return value.hex
The actual AttributeError is masked and re-raised as a TypeError
.
Preliminary investigation showed us that value
is actual an uuid.UUID
instance.
Analysis + Logging we added
We’ve added a lot of logging to this method to be able to figure out the problem. The result is that the method now looks like this:
def get_db_prep_value(self, value, connection, prepared=False):
import logging
import inspect
logger = logging.getLogger('smartscan')
if value is None:
return None
logger.warning('Value id before isinstance check: %s', id(value))
if not isinstance(value, uuid.UUID):
logger.warning('Actual type: %s', type(value))
logger.warning('Is isinstance lying? %s', type(value) == uuid.UUID)
logger.warning('uuid module used: %s', value.__class__.__module__)
if value.__class__ is not unicode:
logger.warning('id(uuid): %s', id(uuid))
logger.warning('id(uuid.UUID): %s', id(uuid.UUID))
logger.warning('id(type(value)): %s', id(type(value)))
logger.warning('module file of `value` class: %s', inspect.getfile(value.__class__))
sanity_check = uuid.uuid4()
logger.warning('Functional isinstance? %s', isinstance(sanity_check, uuid.UUID) is True)
logger.warning('Functional isinstance2? %s', isinstance(u'foo', unicode) is True)
logger.warning(
'Failed isinstance check, uuid module: %s',
uuid.__file__
)
logger.warning('Value id after isinstance check: %s', id(value))
try:
logger.warning('Value id before cast: %s', id(value))
value = uuid.UUID(value)
logger.warning('Value id after cast: %s', id(value))
except AttributeError:
logger.exception('Failed cast: value type and id: %s, %s', type(value), id(value))
raise TypeError(self.error_messages['invalid'] % {'value': value})
if connection.features.has_native_uuid_field:
return value
return value.hex
with sample logging output:
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Actual type: <type 'unicode'>
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:30 smartscan 2356 948 uuid module used: __builtin__
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before cast: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after cast: 120038792
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Actual type: <type 'unicode'>
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:30 smartscan 2356 948 uuid module used: __builtin__
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before cast: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after cast: 120038904
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Actual type: <type 'unicode'>
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:30 smartscan 2356 948 uuid module used: __builtin__
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before cast: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after cast: 970260040
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Actual type: <type 'unicode'>
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:30 smartscan 2356 948 uuid module used: __builtin__
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after isinstance check: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id before cast: 152464528
WARNING May, 17 2017 13:43:30 smartscan 2356 948 Value id after cast: 416975280
INFO May, 17 2017 13:43:30 smartscan.pdf2xmlapp.pdf_handler 2356 948 Received PDF for decoding ...
INFO May, 17 2017 13:43:30 smartscan.pdf2xmlapp.pdf_handler 2356 948 Start pre-parsing with template 1
INFO May, 17 2017 13:43:30 smartscan.pdf2xmlapp.utils 2356 948 Found a fuzzy ('0025_602988') via unique_identifier 'NAR'
INFO May, 17 2017 13:43:30 smartscan.pdf2xmlapp.utils 2356 948 Found exactly 1 template: '0025_602988_en'.
INFO May, 17 2017 13:43:30 smartscan.pdf2xmlapp.pdf_handler 2356 948 Start full parsing PDF with template 43
INFO May, 17 2017 13:43:31 smartscan.pdf2xmlapp.pdf_handler 2356 948 Done full parsing PDF with template 43
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id before isinstance check: 152464528
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Actual type: <type 'unicode'>
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:31 smartscan 2356 948 uuid module used: __builtin__
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id after isinstance check: 152464528
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id before cast: 152464528
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id after cast: 391117624
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id before isinstance check: 148428392
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Actual type: <class 'uuid.UUID'>
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:31 smartscan 2356 948 uuid module used: uuid
WARNING May, 17 2017 13:43:31 smartscan 2356 948 id(uuid): 43429848
WARNING May, 17 2017 13:43:31 smartscan 2356 948 id(uuid.UUID): 41308792
WARNING May, 17 2017 13:43:31 smartscan 2356 948 id(type(value)): 416421896
WARNING May, 17 2017 13:43:31 smartscan 2356 948 module file of `value` class: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Functional isinstance? True
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Functional isinstance2? True
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id after isinstance check: 148428392
WARNING May, 17 2017 13:43:31 smartscan 2356 948 Value id before cast: 148428392
ERROR May, 17 2017 13:43:31 smartscan 2356 948 Failed cast: value type and id: <class 'uuid.UUID'>, 148428392
Traceback (most recent call last):
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 2425, in get_db_prep_value
value = uuid.UUID(value)
File "C:\IBM\python27\Lib\uuid.py", line 133, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'UUID' object has no attribute 'replace'
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Value id before isinstance check: 148428392
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Actual type: <class 'uuid.UUID'>
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:32 smartscan 2356 948 uuid module used: uuid
WARNING May, 17 2017 13:43:32 smartscan 2356 948 id(uuid): 43429848
WARNING May, 17 2017 13:43:32 smartscan 2356 948 id(uuid.UUID): 41308792
WARNING May, 17 2017 13:43:32 smartscan 2356 948 id(type(value)): 416421896
WARNING May, 17 2017 13:43:32 smartscan 2356 948 module file of `value` class: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Functional isinstance? True
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Functional isinstance2? True
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Value id after isinstance check: 148428392
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Value id before cast: 148428392
ERROR May, 17 2017 13:43:32 smartscan 2356 948 Failed cast: value type and id: <class 'uuid.UUID'>, 148428392
Traceback (most recent call last):
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 2425, in get_db_prep_value
value = uuid.UUID(value)
File "C:\IBM\python27\Lib\uuid.py", line 133, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'UUID' object has no attribute 'replace'
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Value id before isinstance check: 148428392
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Actual type: <class 'uuid.UUID'>
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:32 smartscan 2356 948 uuid module used: uuid
WARNING May, 17 2017 13:43:32 smartscan 2356 948 id(uuid): 43429848
WARNING May, 17 2017 13:43:32 smartscan 2356 948 id(uuid.UUID): 41308792
WARNING May, 17 2017 13:43:32 smartscan 2356 948 id(type(value)): 416421896
WARNING May, 17 2017 13:43:32 smartscan 2356 948 module file of `value` class: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Functional isinstance? True
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Functional isinstance2? True
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Value id after isinstance check: 148428392
WARNING May, 17 2017 13:43:32 smartscan 2356 948 Value id before cast: 148428392
ERROR May, 17 2017 13:43:32 smartscan 2356 948 Failed cast: value type and id: <class 'uuid.UUID'>, 148428392
Traceback (most recent call last):
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 2425, in get_db_prep_value
value = uuid.UUID(value)
File "C:\IBM\python27\Lib\uuid.py", line 133, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'UUID' object has no attribute 'replace'
ERROR May, 17 2017 13:43:31 django.request 2356 948 Internal Server Error: /smartscan/viewer/side-by-side/template/43/
Traceback (most recent call last):
File "D:\redacted\backend\env\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "D:\redacted\backend\env\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\redacted\backend\env\lib\site-packages\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "D:\redacted\smartscan\backend\src\smartscan\viewer\views.py", line 263, in dispatch
return super(SideBySideView, self).dispatch(request, *args, **kwargs)
File "D:\redacted\backend\env\lib\site-packages\django\contrib\auth\mixins.py", line 56, in dispatch
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
File "D:\redacted\backend\env\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "D:\redacted\backend\env\lib\site-packages\django\views\generic\edit.py", line 279, in post
return super(BaseUpdateView, self).post(request, *args, **kwargs)
File "D:\redacted\backend\env\lib\site-packages\django\views\generic\edit.py", line 222, in post
return self.form_valid(form)
File "D:\redacted\smartscan\backend\src\smartscan\viewer\views.py", line 401, in form_valid
return HttpResponseRedirect(self.get_success_url())
File "D:\redacted\smartscan\backend\src\smartscan\viewer\views.py", line 368, in get_success_url
self.set_invoice_data(invoice_data)
File "D:\redacted\smartscan\backend\src\smartscan\viewer\views.py", line 337, in set_invoice_data
invoice_data.save()
File "D:\redacted\backend\env\lib\site-packages\django\db\models\base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\base.py", line 736, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\base.py", line 801, in _save_table
forced_update)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\base.py", line 851, in _do_update
return filtered._update(values) > 0
File "D:\redacted\backend\env\lib\site-packages\django\db\models\query.py", line 645, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\sql\compiler.py", line 1149, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\sql\compiler.py", line 837, in execute_sql
sql, params = self.as_sql()
File "D:\redacted\backend\env\lib\site-packages\django\db\models\sql\compiler.py", line 1137, in as_sql
where, params = self.compile(self.query.where)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\sql\compiler.py", line 366, in compile
sql, params = node.as_sql(self, self.connection)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\sql\where.py", line 79, in as_sql
sql, params = compiler.compile(child)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\sql\compiler.py", line 366, in compile
sql, params = node.as_sql(self, self.connection)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\lookups.py", line 158, in as_sql
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\lookups.py", line 91, in process_rhs
return self.get_db_prep_lookup(value, connection)
File "D:\redacted\backend\env\lib\site-packages\django\db\models\lookups.py", line 62, in get_db_prep_lookup
self.lookup_name, value, connection, prepared=True))
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 776, in get_db_prep_lookup
prepared=prepared)]
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 2429, in get_db_prep_value
raise TypeError(self.error_messages['invalid'] % {'value': value})
TypeError: '47ff7acf-eefa-4a86-8fa2-1609fdfe8278' is not a valid UUID.
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Value id before isinstance check: 148428392
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Actual type: <class 'uuid.UUID'>
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:33 smartscan 2356 948 uuid module used: uuid
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(uuid): 43429848
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(uuid.UUID): 41308792
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(type(value)): 416421896
WARNING May, 17 2017 13:43:33 smartscan 2356 948 module file of `value` class: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Functional isinstance? True
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Functional isinstance2? True
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Value id after isinstance check: 148428392
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Value id before cast: 148428392
ERROR May, 17 2017 13:43:33 smartscan 2356 948 Failed cast: value type and id: <class 'uuid.UUID'>, 148428392
Traceback (most recent call last):
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 2425, in get_db_prep_value
value = uuid.UUID(value)
File "C:\IBM\python27\Lib\uuid.py", line 133, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'UUID' object has no attribute 'replace'
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Value id before isinstance check: 148428392
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Actual type: <class 'uuid.UUID'>
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:33 smartscan 2356 948 uuid module used: uuid
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(uuid): 43429848
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(uuid.UUID): 41308792
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(type(value)): 416421896
WARNING May, 17 2017 13:43:33 smartscan 2356 948 module file of `value` class: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Functional isinstance? True
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Functional isinstance2? True
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Failed isinstance check, uuid module: C:\IBM\python27\Lib\uuid.pyc
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Value id after isinstance check: 148428392
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Value id before cast: 148428392
ERROR May, 17 2017 13:43:33 smartscan 2356 948 Failed cast: value type and id: <class 'uuid.UUID'>, 148428392
Traceback (most recent call last):
File "D:\redacted\backend\env\lib\site-packages\django\db\models\fields\__init__.py", line 2425, in get_db_prep_value
value = uuid.UUID(value)
File "C:\IBM\python27\Lib\uuid.py", line 133, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'UUID' object has no attribute 'replace'
High level observations
Things go well for a while, especially when the input is indeed a string, as can be noticed from the start of the logging output. Note that on line 48 of the logging output we are indeed dealing with a uuid.UUID
instance and it leads to a crash.
Restarting Apache ‘solves’ the issue for a while, until it doesn’t anymore.
Diving deeper
The uuid module to be used appears to be the right standard lib module. But, when comparing the IDs of the classes, we see an unexpected result. In a plain python shell:
>>> import uuid
>>> some_uuid = uuid.uuid4()
>>> id(type(some_uuid)) == id(uuid.UUID)
True
However, the logging output has a different result:
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Actual type: <class 'uuid.UUID'>
WARNING May, 17 2017 13:43:33 smartscan 2356 948 Is isinstance lying? False
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(uuid.UUID): 41308792
WARNING May, 17 2017 13:43:33 smartscan 2356 948 id(type(value)): 416421896
The only way how I managed to reproduce a similar thing like this, is by fiddling with sys.modules
, example shell session:
>>> import uuid
>>> some_uuid = uuid.uuid4()
>>> isinstance(some_uuid, uuid.UUID)
True # as expected
>>> del uuid
>>> isinstance(some_uuid, uuid.UUID)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'uuid' is not defined # as expected
>>> import uuid
>>> isinstance(some_uuid, uuid.UUID)
True # as expected, since the module is loaded from the cache - `sys.modules['uuid']`
>>> import sys
>>> del sys.modules['uuid']
>>> isinstance(some_uuid, uuid.UUID)
True # as expected, since we still have a reference in the shell session
>>> del uuid
>>> isinstance(some_uuid, uuid.UUID)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'uuid' is not defined # as expected, name reference is dropped
>>> import uuid # freshly loaded, since it was no longer in `sys.modules`
>>> isinstance(some_uuid, uuid.UUID)
False
Questions?
So, we’re kind of clueless on this one. What’s happening? Why does it seems like sys.modules
is getting mutuated? Is there a thread-safety issue somehow?
Next steps
We’re going to try and set up an instance with Python 3 and see if the problem persists, but can’t give any timeframe on that.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (5 by maintainers)
@felipinbombin Do you have
WSGIApplicationGroup
set to%{GLOBAL}
in your Apache config.Hi friends, Is the error solved after adding WSGIApplicationGroup %{GLOBAL} ??