Skip to content

[Fix] Serve drops some attributes at serialization#46680

Merged
SunMarc merged 3 commits into
mainfrom
fix-serve-serialization
Jun 16, 2026
Merged

[Fix] Serve drops some attributes at serialization#46680
SunMarc merged 3 commits into
mainfrom
fix-serve-serialization

Conversation

@remi-or

@remi-or remi-or commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes an issue in serve.
In chat_completion.py, we create a subclass of ChatCompletionMessage in which reasoning_content is a field. When this class is serialized, the field is lost because pydantic v2 uses the serializer from the annotated class (the original ChatCompletionMessage that was subclassed) rather than the runtime class (the subclass that we instantiate). Since the parent class, and its serializer, don't know about this subclass's attribute, it is lost at serialisation.

This PR fixes this by removing the subclass and rather passing reasoning_content as an extra field, which is allowed by the base class and serialized as well.
This fixes 6 tests in test_serve.py

Since I am not familiar with pydantic, this may not be the best way to resolve this. On the off-chance it is, happy to help.

@remi-or remi-or requested a review from SunMarc June 16, 2026 01:33
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

Copy link
Copy Markdown
Contributor

CI Dashboard: View test results in Grafana

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've fixed this issue on this PR but still waiting for @Rocketknight1 PR to be merged. #46267
Still the solution here seems a bit more elegant than what i did so I will update my PR later on.

@SunMarc SunMarc added this pull request to the merge queue Jun 16, 2026
Merged via the queue into main with commit e418910 Jun 16, 2026
37 checks passed
@SunMarc SunMarc deleted the fix-serve-serialization branch June 16, 2026 15:00
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.

3 participants