Skip to content

Commit

Permalink
Catch HTTPStatusErrors on delete kernel session (#101)
Browse files Browse the repository at this point in the history
* Catch HTTPStatusErrors on delete kernel session

* add changelog

* Bump version: 0.0.16 → 0.0.17
  • Loading branch information
rohitsanj authored Dec 16, 2022
1 parent 2aace63 commit cdb999d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.16
current_version = 0.0.17
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize =
{major}.{minor}.{patch}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.0.17] - 2022-12-16
### Changed
- Catch all HTTPStatusErrors when trying to delete the kernel session after successful execution

## [0.0.16] - 2022-12-14
### Changed
Expand Down
2 changes: 1 addition & 1 deletion papermill_origami/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.0.16"
version = "0.0.17"
7 changes: 7 additions & 0 deletions papermill_origami/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ async def papermill_execute_cells(self):
"Timed out while deleting kernel session for file id %s",
self.file.id,
)
except httpx.HTTPStatusError as e:
# Ignore any HTTP errors that occur while deleting the kernel session
logger.warning(
"Failed to delete kernel session for file id %s. Error: %s",
self.file.id,
e,
)

def _get_timeout(self, cell: Optional[NotebookNode]) -> int:
"""Helper to fetch a timeout as a value or a function to be run against a cell"""
Expand Down
20 changes: 20 additions & 0 deletions papermill_origami/tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from unittest.mock import ANY

import httpx
import nbformat
import pytest
from nbclient.exceptions import CellExecutionError
Expand Down Expand Up @@ -394,3 +395,22 @@ async def test_kernel_session_is_not_deleted_after_failed_execution(

# Assert that the kernel session was not deleted
noteable_engine.client.delete_kernel_session.assert_not_called()

@pytest.mark.parametrize(
"exception",
[
httpx.ReadTimeout("fake message"),
httpx.HTTPStatusError("fake message", request=None, response=None),
],
)
async def test_catch_delete_kernel_session_errors(
self, file_content, noteable_engine, exception
):
noteable_engine.client.delete_kernel_session.side_effect = exception
try:
await noteable_engine.execute(
file_id='fake_id',
noteable_nb=file_content,
)
except exception.__class__:
pytest.fail("papermill_execute_cells should catch delete_kernel_session errors")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[tool.poetry]
name = "papermill-origami"
version = "0.0.16"
version = "0.0.17"
description = "The noteable API interface"
authors = ["Matt Seal <[email protected]>"]
maintainers = ["Matt Seal <[email protected]>"]
Expand Down

0 comments on commit cdb999d

Please sign in to comment.