Skip to content

fix(sse): preserve empty data lines when formatting SSE#15618

Closed
MatiasFormoso wants to merge 1 commit into
fastapi:masterfrom
MatiasFormoso:fix-sse-empty-data-lines
Closed

fix(sse): preserve empty data lines when formatting SSE#15618
MatiasFormoso wants to merge 1 commit into
fastapi:masterfrom
MatiasFormoso:fix-sse-empty-data-lines

Conversation

@MatiasFormoso
Copy link
Copy Markdown

Summary

  • preserve explicit empty payloads in format_sse_event(data_str=...) by emitting a data: line
  • normalize CRLF/CR to LF before splitting data lines for stable SSE wire output
  • add focused tests for empty data and trailing-newline behavior

Why

format_sse_event(data_str='') currently emits no data: line, which can drop an intended empty event payload. This change keeps empty and trailing lines explicit in the SSE output.

Tests

  • python -m pytest -c nul tests/test_sse.py -k format_sse_event -q
  • python -m pytest -c nul tests/test_sse.py -q

Made with Cursor

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 27, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing MatiasFormoso:fix-sse-empty-data-lines (4a9561a) with master (59d4a80)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (dbfd55c) during the generation of this report, so 59d4a80 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@YuriiMotov
Copy link
Copy Markdown
Member

@MatiasFormoso, thanks!
We already have PR #15515 that fixes this. The test case with empty string was missing, I suggested to add it in the comments of that PR.

I'll close this to avoid having duplicates

@YuriiMotov YuriiMotov closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants