Repository navigation
🐛 Fix response_model_include/exclude ignored for ServerSentEvent data - #16147
Closed
Shriprasad-P wants to merge 1 commit into
Closed
Shriprasad-P wants to merge 1 commit into
Shriprasad-P wants to merge 1 commit into
Conversation
ServerSentEvent(data=...) skipped route-level include/exclude when serializing models and dicts, unlike plain streamed items.
Member
|
Thanks for your interest and efforts, but let's keep it closed until maintainers can review the discussion #15703 and decide how to handle it. We are trying to keep things clean and ask to only open PRs when it's explicitly requested by maintainers.
Thanks for understanding! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ServerSentEvent(data=...)serializes payloads viamodel_dump_json()/jsonable_encoder()without forwarding route-levelresponse_model_includeorresponse_model_exclude.Plain stream items already pass these options through
ModelField.serialize_json(), so the same model can serialize differentlydepending on how it is yielded:
Fix
Forward
include=response_model_includeandexclude=response_model_excludein the explicit
ServerSentEventbranch for both:model_dump_json(...)jsonable_encoder(...)raw_data, strings, event metadata (event/id/retry/comment),and non-SSE response serialization are unchanged.
This is intentionally scoped to include/exclude only, so it can coexist with:
ServerSentEventdata in SSE streams #16144 (response_model_by_alias)response_model_exclude_unset/exclude_defaults/exclude_none)Tests
Added regressions in
tests/test_sse.pycovering:response_model_includeonServerSentEvent(data=model)response_model_excludeonServerSentEvent(data=model)jsonable_encoderServerSentEvent-wrapped parityraw_data/ string data unchangedThe new tests fail on current
masterand pass with this change.Checks
Checklist
response_model_*options)