@@ -71,7 +71,9 @@ def on_close(self):
71
71
self .event_logger .remove_listener (listener = self .event_listener )
72
72
73
73
74
- def validate_model (data : dict [str , Any ], schema : jupyter_events .schema .EventSchema ) -> None :
74
+ def validate_model (
75
+ data : dict [str , Any ], registry : jupyter_events .schema_registry .SchemaRegistry
76
+ ) -> None :
75
77
"""Validates for required fields in the JSON request body and verifies that
76
78
a registered schema/version exists"""
77
79
required_keys = {"schema_id" , "version" , "data" }
@@ -81,9 +83,7 @@ def validate_model(data: dict[str, Any], schema: jupyter_events.schema.EventSche
81
83
raise Exception (message )
82
84
schema_id = cast (str , data .get ("schema_id" ))
83
85
version = cast (int , data .get ("version" ))
84
- if schema is None :
85
- message = f"Unregistered schema: `{ schema_id } `"
86
- raise Exception (message )
86
+ schema = registry .get (schema_id )
87
87
if schema .version != version :
88
88
message = f"Unregistered version: `{ version } ` for `{ schema_id } `"
89
89
raise Exception (message )
@@ -121,10 +121,9 @@ async def post(self):
121
121
raise web .HTTPError (400 , "No JSON data provided" )
122
122
123
123
try :
124
- schema = self .event_logger .schemas .get (cast (str , payload .get ("schema_id" )))
125
- validate_model (payload , schema )
124
+ validate_model (payload , self .event_logger .schemas )
126
125
self .event_logger .emit (
127
- schema_id = schema . id ,
126
+ schema_id = cast ( str , payload . get ( "schema_id" )) ,
128
127
data = cast ("Dict[str, Any]" , payload .get ("data" )),
129
128
timestamp_override = get_timestamp (payload ),
130
129
)
0 commit comments