Browse Source

♻️ Refactor ServerSentEvent to use id: str

pull/15030/head
Sebastián Ramírez 4 months ago
parent
commit
d707105053
  1. 8
      fastapi/sse.py

8
fastapi/sse.py

@ -33,8 +33,8 @@ class EventSourceResponse(StreamingResponse):
media_type = "text/event-stream"
def _check_id_no_null(v: int | str | None) -> int | str | None:
if v is not None and "\0" in str(v):
def _check_id_no_null(v: str | None) -> str | None:
if v is not None and "\0" in v:
raise ValueError("SSE 'id' must not contain null characters")
return v
@ -96,7 +96,7 @@ class ServerSentEvent(BaseModel):
),
] = None
id: Annotated[
int | str | None,
str | None,
AfterValidator(_check_id_no_null),
Doc(
"""
@ -162,7 +162,7 @@ def format_sse_event(
),
] = None,
id: Annotated[
int | str | None,
str | None,
Doc(
"""
Optional event ID (`id:` field).

Loading…
Cancel
Save