Skip to content

Commit 2563bae

Browse files
allstriveblink1073
andauthored
Make kernel_id as a conditional optional field (#1300)
Co-authored-by: Steven Silvester <[email protected]>
1 parent 6658e2f commit 2563bae

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

jupyter_server/event_schemas/kernel_actions/v1.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ description: |
77
type: object
88
required:
99
- action
10-
- kernel_id
1110
- msg
1211
properties:
1312
action:
@@ -39,7 +38,7 @@ properties:
3938
description: |
4039
Kernel id.
4140
42-
This is a required field.
41+
This is a required field for all actions and statuses except action start with status error.
4342
kernel_name:
4443
type: string
4544
description: |
@@ -69,3 +68,13 @@ properties:
6968
type: string
7069
description: |
7170
Description of the event specified in action.
71+
if:
72+
not:
73+
properties:
74+
status:
75+
const: error
76+
action:
77+
const: start
78+
then:
79+
required:
80+
- kernel_id

jupyter_server/services/kernels/kernelmanager.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -738,28 +738,31 @@ async def wrapped_method(self, *args, **kwargs):
738738
# If the method succeeds, emit a success event.
739739
try:
740740
out = await method(self, *args, **kwargs)
741+
data = {
742+
"kernel_name": self.kernel_name,
743+
"action": action,
744+
"status": "success",
745+
"msg": success_msg.format(
746+
kernel_id=self.kernel_id, kernel_name=self.kernel_name, action=action
747+
),
748+
}
749+
if self.kernel_id:
750+
data["kernel_id"] = self.kernel_id
741751
self.emit(
742752
schema_id="https://events.jupyter.org/jupyter_server/kernel_actions/v1",
743-
data={
744-
"kernel_id": self.kernel_id,
745-
"kernel_name": self.kernel_name,
746-
"action": action,
747-
"status": "success",
748-
"msg": success_msg.format(
749-
kernel_id=self.kernel_id, kernel_name=self.kernel_name, action=action
750-
),
751-
},
753+
data=data,
752754
)
753755
return out
754756
# If the method fails, emit a failed event.
755757
except Exception as err:
756758
data = {
757-
"kernel_id": self.kernel_id,
758759
"kernel_name": self.kernel_name,
759760
"action": action,
760761
"status": "error",
761762
"msg": str(err),
762763
}
764+
if self.kernel_id:
765+
data["kernel_id"] = self.kernel_id
763766
# If the exception is an HTTPError (usually via a gateway request)
764767
# log the status_code and HTTPError log_message.
765768
if isinstance(err, web.HTTPError):

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ filterwarnings = [
277277
"ignore:datetime.utcnow:DeprecationWarning",
278278
# from nbformat
279279
"ignore:Importing ErrorTree directly from the jsonschema package:DeprecationWarning",
280+
# From jupyter_events
281+
"module:jsonschema.RefResolver is deprecated as of:DeprecationWarning",
280282
# ignore pytest warnings.
281283
"ignore:::_pytest",
282284
]

0 commit comments

Comments
 (0)