Commit 3841bde5 authored by Yusei Tahara's avatar Yusei Tahara

erp5_data_notebook: Don't try to serialize well known unserializable objects...

erp5_data_notebook: Don't try to serialize well known unserializable objects and ignore any exceptions happened during serialization otherwise jupyter becomes permanent unusable state.
parent acf692cd
......@@ -28,6 +28,10 @@ from ipykernel.jsonutil import json_clean, encode_images
import threading
display_data_wrapper_lock = threading.Lock()
# Well known unserializable types
from Record import Record
well_known_unserializable_type_tuple = (ModuleType, Record,)
def Base_executeJupyter(self, python_expression=None, reference=None, \
title=None, request_reference=False, **kw):
# Check permissions for current user and display message to non-authorized user
......@@ -460,7 +464,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
volatile_variable_list.append('__builtins__')
for key, val in user_context.items():
if not key in globals_dict.keys() and not isinstance(val, ModuleType) and not key in volatile_variable_list:
if not key in globals_dict.keys() and not isinstance(val, well_known_unserializable_type_tuple) and not key in volatile_variable_list:
if canSerialize(val):
notebook_context['variables'][key] = val
else:
......@@ -530,7 +534,11 @@ def canSerialize(obj):
# Need to unwrap the variable, otherwise we get a TypeError, because
# objects cannot be pickled while inside an acquisition wrapper.
unwrapped_obj = Acquisition.aq_base(obj)
try:
writer = ObjectWriter(unwrapped_obj)
except:
# Ignore any exceptions, otherwise Jupyter becomes permanent unusble state.
return False
for obj in writer:
try:
writer.serialize(obj)
......
......@@ -46,12 +46,13 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W:390, 10: Use of exec (exec-used)</string>
<string>W:433, 10: Use of exec (exec-used)</string>
<string>W:446, 10: Use of exec (exec-used)</string>
<string>W:539, 6: No exception type(s) specified (bare-except)</string>
<string>W:851, 6: Use of exec (exec-used)</string>
<string>W:1086, 2: Redefining name \'IFrame\' from outer scope (line 4) (redefined-outer-name)</string>
<string>W:394, 10: Use of exec (exec-used)</string>
<string>W:437, 10: Use of exec (exec-used)</string>
<string>W:450, 10: Use of exec (exec-used)</string>
<string>W:539, 4: No exception type(s) specified (bare-except)</string>
<string>W:547, 6: No exception type(s) specified (bare-except)</string>
<string>W:859, 6: Use of exec (exec-used)</string>
<string>W:1094, 2: Redefining name \'IFrame\' from outer scope (line 4) (redefined-outer-name)</string>
</tuple>
</value>
</item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment