papermill
papermill copied to clipboard
Does not catch certain query magic error? (UsageError: Cell magic `%%bigquery` not found.)
Normally without running %load_ext google.cloud.bigquery
, using %%bigquery
would throw this error, but when executing a notebook via papermill this doesn't seem to be caught as an exception
Likely this is a result of the magic function not raising an exception. I'd need to investigate some to determine if that's the case. If so, then this should probably be an issue on that project to raise rather than silently fail.
If it's any help at all, I traced the error back to ipython (https://github.com/ipython/ipython/blob/a8165da9102a62203c824f8cb59988e188fc6032/IPython/core/magics/basic.py), where it raised the UsageError
, which indeed you see it in the output of cells in the notebook, but it's not acting like an exception
Sorry I got very sick and backlogged on items.
If it's raising UsageError
from the linked code it should halt and send an error status that halts execution as you'd expect. Do you have a minimal working example I could reproduce with? That'd help with debugging at this point.
@MSeal I am also seeing this error occur with kql magic command (%%kql) which executes the parameterized notebook but then has an error later on the usage.
user % papermill simpleKQLmagic3.ipynb output_simple.ipynb
Input Notebook: simpleKQLmagic3.ipynb
Output Notebook: output_simple.ipynb
Executing: 0%| | 0/7 [00:00<?, ?cell/s]Executing notebook with kernel: python3
Executing: 43%|ââââââââââââââââââââ | 3/7 [00:08<00:10, 2.60s/cell]2020-11-25 16:29:03,346 - INFO - start parent_monitor for parent id: 20462
2020-11-25 16:29:03,346 - INFO - * parent id: 20462
2020-11-25 16:29:03,346 - INFO - * Base folder: /Users/xxx
2020-11-25 16:29:03,346 - INFO - * Folder list: ['.kqlmagic/temp_files/b40af28a-42a4-4b47-8188-953c3f57d3cc']
2020-11-25 16:29:03,346 - INFO - *
2020-11-25 16:29:03,346 - INFO - ****
* Serving Flask app "kqlmagic_temp_files_server" (lazy loading)
* Environment: development
* Debug mode: off
* Running on http://127.0.0.1:50197/ (Press CTRL+C to quit)
127.0.0.1 - - [25/Nov/2020 16:29:04] "GET /ping?kernelid=b40af28a-42a4-4b47-8188-953c3f57d3cc HTTP/1.1" 200 -
2020-11-25 16:29:04,350 - INFO - ParentUnixMonitor for ppid 20462, parent is running.
Executing: 57%|âââââââââââââââââââââââââââ | 4/7 [00:12<00:08, 2.89s/cell]2020-11-25 16:29:06,919 - INFO - OS_EXIT code: 0!!!
2020-11-25 16:29:06,920 - INFO - start to clean folder: /Users/vasubhog/.kqlmagic/temp_files/b40af28a-42a4-4b47-8188-953c3f57d3cc
2020-11-25 16:29:06,920 - INFO - clean folder: /Users/vasubhog/.kqlmagic/temp_files/b40af28a-42a4-4b47-8188-953c3f57d3cc done
2020-11-25 16:29:06,920 - INFO - clean finished
Executing: 86%|ââââââââââââââââââââââââââââââââââââââââ | 6/7 [00:13<00:02, 2.19s/cell]
The input notebook has no issue running the notebook, however, the papermill executed notebook has this usage error which does not get noted by papermill.
Any suggestions?
It seems that usage error will not be treated as a normal exception, otherwise the exitCode of papermill would not be 0.
magic.ipynb:
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%non_exsiting_magic_123 a=1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Unreachable\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
out.ipynb:
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2021-01-11T08:26:13.816189Z",
"iopub.status.busy": "2021-01-11T08:26:13.815776Z",
"iopub.status.idle": "2021-01-11T08:26:13.818084Z",
"shell.execute_reply": "2021-01-11T08:26:13.817254Z"
},
"papermill": {
"duration": 0.010433,
"end_time": "2021-01-11T08:26:13.818275",
"exception": true,
"start_time": "2021-01-11T08:26:13.807842",
"status": "failed"
},
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"UsageError: Line magic function `%non_exsiting_magic_123` not found.\n"
]
}
],
"source": [
"%non_exsiting_magic_123 a=1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"papermill": {
"duration": null,
"end_time": null,
"exception": null,
"start_time": null,
"status": "pending"
},
"tags": []
},
"outputs": [],
"source": [
"print(\"Unreachable\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
},
"papermill": {
"default_parameters": {},
"duration": 0.911699,
"end_time": "2021-01-11T08:26:14.122548",
"environment_variables": {},
"exception": true,
"input_path": "magic.ipynb",
"output_path": "out.ipynb",
"parameters": {},
"start_time": "2021-01-11T08:26:13.210849",
"version": "2.2.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
(base) â heyw papermill magic.ipynb out.ipynb --log-output && echo $?
Input Notebook: magic.ipynb
Output Notebook: out.ipynb
Executing notebook with kernel: python3
Executing Cell 1---------------------------------------
UsageError: Line magic function %non_exsiting_magic_123
not found.
Ending Cell 1------------------------------------------ 0
(base) â heyw papermill --version 2.2.2 from /home/mk/anaconda3/lib/python3.8/site-packages/papermill-2.2.2-py3.8.egg/papermill/cli.py (3.8.3)