Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kernel_id as a conditional optional field #1300

Merged
merged 4 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions jupyter_server/event_schemas/kernel_actions/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description: |
type: object
required:
- action
- kernel_id
- msg
properties:
action:
Expand Down Expand Up @@ -39,7 +38,7 @@ properties:
description: |
Kernel id.

This is a required field.
allstrive marked this conversation as resolved.
Show resolved Hide resolved
This is a required field for all actions and statuses except action start with status error.
kernel_name:
type: string
description: |
Expand Down Expand Up @@ -69,3 +68,13 @@ properties:
type: string
description: |
Description of the event specified in action.
if:
allstrive marked this conversation as resolved.
Show resolved Hide resolved
not:
properties:
status:
const: error
action:
const: start
then:
required:
- kernel_id
23 changes: 13 additions & 10 deletions jupyter_server/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,28 +738,31 @@ async def wrapped_method(self, *args, **kwargs):
# If the method succeeds, emit a success event.
try:
out = await method(self, *args, **kwargs)
data = {
"kernel_name": self.kernel_name,
"action": action,
"status": "success",
"msg": success_msg.format(
kernel_id=self.kernel_id, kernel_name=self.kernel_name, action=action
),
}
if self.kernel_id:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is required to ensure that , it doesn't produce message with value
kernel_id : null as that will fail with current schema. The current schema won't accept null value.

data["kernel_id"] = self.kernel_id
self.emit(
schema_id="https://events.jupyter.org/jupyter_server/kernel_actions/v1",
data={
"kernel_id": self.kernel_id,
"kernel_name": self.kernel_name,
"action": action,
"status": "success",
"msg": success_msg.format(
kernel_id=self.kernel_id, kernel_name=self.kernel_name, action=action
),
},
data=data,
)
return out
# If the method fails, emit a failed event.
except Exception as err:
data = {
"kernel_id": self.kernel_id,
"kernel_name": self.kernel_name,
"action": action,
"status": "error",
"msg": str(err),
}
if self.kernel_id:
data["kernel_id"] = self.kernel_id
# If the exception is an HTTPError (usually via a gateway request)
# log the status_code and HTTPError log_message.
if isinstance(err, web.HTTPError):
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ filterwarnings = [
"ignore:datetime.utcnow:DeprecationWarning",
# from nbformat
"ignore:Importing ErrorTree directly from the jsonschema package:DeprecationWarning",
# From jupyter_events
"module:jsonschema.RefResolver is deprecated as of:DeprecationWarning",
# ignore pytest warnings.
"ignore:::_pytest",
]
Expand Down