Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Oct 29, 2024
1 parent 3abb802 commit 80307ab
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions jupyter_server/services/events/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def on_close(self):
self.event_logger.remove_listener(listener=self.event_listener)


def validate_model(data: dict[str, Any], schema: jupyter_events.schema.EventSchema) -> None:
def validate_model(
data: dict[str, Any], registry: jupyter_events.schema_registry.SchemaRegistry
) -> None:
"""Validates for required fields in the JSON request body and verifies that
a registered schema/version exists"""
required_keys = {"schema_id", "version", "data"}
Expand All @@ -81,9 +83,7 @@ def validate_model(data: dict[str, Any], schema: jupyter_events.schema.EventSche
raise Exception(message)
schema_id = cast(str, data.get("schema_id"))
version = cast(int, data.get("version"))
if schema is None:
message = f"Unregistered schema: `{schema_id}`"
raise Exception(message)
schema = registry.get(cast(str, schema_id))
if schema.version != version:
message = f"Unregistered version: `{version}` for `{schema_id}`"
raise Exception(message)
Expand Down Expand Up @@ -121,10 +121,9 @@ async def post(self):
raise web.HTTPError(400, "No JSON data provided")

try:
schema = self.event_logger.schemas.get(cast(str, payload.get("schema_id")))
validate_model(payload, schema)
validate_model(payload, self.event_logger.schemas)
self.event_logger.emit(
schema_id=schema.id,
schema_id=cast(str, payload.get("schema_id")),
data=cast("Dict[str, Any]", payload.get("data")),
timestamp_override=get_timestamp(payload),
)
Expand Down

0 comments on commit 80307ab

Please sign in to comment.