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 ...@@ -28,6 +28,10 @@ from ipykernel.jsonutil import json_clean, encode_images
import threading import threading
display_data_wrapper_lock = threading.Lock() 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, \ def Base_executeJupyter(self, python_expression=None, reference=None, \
title=None, request_reference=False, **kw): title=None, request_reference=False, **kw):
# Check permissions for current user and display message to non-authorized user # 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): ...@@ -460,7 +464,7 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
volatile_variable_list.append('__builtins__') volatile_variable_list.append('__builtins__')
for key, val in user_context.items(): 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): if canSerialize(val):
notebook_context['variables'][key] = val notebook_context['variables'][key] = val
else: else:
...@@ -530,7 +534,11 @@ def canSerialize(obj): ...@@ -530,7 +534,11 @@ def canSerialize(obj):
# Need to unwrap the variable, otherwise we get a TypeError, because # Need to unwrap the variable, otherwise we get a TypeError, because
# objects cannot be pickled while inside an acquisition wrapper. # objects cannot be pickled while inside an acquisition wrapper.
unwrapped_obj = Acquisition.aq_base(obj) unwrapped_obj = Acquisition.aq_base(obj)
try:
writer = ObjectWriter(unwrapped_obj) writer = ObjectWriter(unwrapped_obj)
except:
# Ignore any exceptions, otherwise Jupyter becomes permanent unusble state.
return False
for obj in writer: for obj in writer:
try: try:
writer.serialize(obj) writer.serialize(obj)
......
...@@ -46,12 +46,13 @@ ...@@ -46,12 +46,13 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W:390, 10: Use of exec (exec-used)</string> <string>W:394, 10: Use of exec (exec-used)</string>
<string>W:433, 10: Use of exec (exec-used)</string> <string>W:437, 10: Use of exec (exec-used)</string>
<string>W:446, 10: Use of exec (exec-used)</string> <string>W:450, 10: Use of exec (exec-used)</string>
<string>W:539, 6: No exception type(s) specified (bare-except)</string> <string>W:539, 4: No exception type(s) specified (bare-except)</string>
<string>W:851, 6: Use of exec (exec-used)</string> <string>W:547, 6: No exception type(s) specified (bare-except)</string>
<string>W:1086, 2: Redefining name \'IFrame\' from outer scope (line 4) (redefined-outer-name)</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> </tuple>
</value> </value>
</item> </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