Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f2858d1

Browse files
committed
Merge pull request #7375 from minrk/empty-execute-result
ensure data, metadata are set in execute_results
2 parents 3c0bbde + e74c163 commit f2858d1

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

IPython/html/static/notebook/js/outputarea.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,17 @@ define([
243243
'text/plain'
244244
];
245245

246-
OutputArea.prototype.validate_mimebundle = function (json) {
247-
/**
248-
* scrub invalid outputs
249-
*/
250-
var data = json.data;
246+
OutputArea.prototype.validate_mimebundle = function (bundle) {
247+
/** scrub invalid outputs */
248+
if (typeof bundle.data !== 'object') {
249+
console.warn("mimebundle missing data", bundle);
250+
bundle.data = {};
251+
}
252+
if (typeof bundle.metadata !== 'object') {
253+
console.warn("mimebundle missing metadata", bundle);
254+
bundle.metadata = {};
255+
}
256+
var data = bundle.data;
251257
$.map(OutputArea.output_types, function(key){
252258
if (key !== 'application/json' &&
253259
data[key] !== undefined &&
@@ -257,7 +263,7 @@ define([
257263
delete data[key];
258264
}
259265
});
260-
return json;
266+
return bundle;
261267
};
262268

263269
OutputArea.prototype.append_output = function (json) {

IPython/kernel/zmq/displayhook.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ def set_parent(self, parent):
5151
self.parent_header = extract_header(parent)
5252

5353
def start_displayhook(self):
54-
self.msg = self.session.msg(u'execute_result', {}, parent=self.parent_header)
54+
self.msg = self.session.msg(u'execute_result', {
55+
'data': {},
56+
'metadata': {},
57+
}, parent=self.parent_header)
5558

5659
def write_output_prompt(self):
5760
"""Write the output prompt."""

0 commit comments

Comments
 (0)