I've encountered the following issue with NotebookEvaluate (note the grouping into 3 distinct cells):
(* Cell 1 *)
$Context
(* "Global`" *)
(* Cell 2 *)
SetOptions[EvaluationCell[], CellContext -> Notebook]
nb3 = NotebookCreate[];
NotebookEvaluate[nb3, InsertResults -> True];
$Context
(* "Notebook$$16$795021`" *)
(* Cell 3 *)
$Context
(* "Notebook$$16$795021`" *)
As can be seen, the NotebookEvaluate cell breaks the $Context of the original notebook.
Am I missing something? Or is this simply a bug? And most importantly, what's the easiest way to fix this?
I could wrap the whole thing inside Block[{$Context=$Context},...] but that doesn't seem right - It doesn't fix the issue properly, as I cannot wrap the Block directly around the NotebookEvaluate, as the context is already wrong there, it just fixes the symptomes later
Related
- NotebookEvaluate breaks notebook's context - As opposed to there, my issue is that the context on the caller site is messed up
- How does the Kernel know the $Context in a localized notebook - This might have something to do with my issue in the sense that the front-end forgets to set the proper context