[BUG] Fix Patch operations reset fields to default if not specified #23650#23676
Closed
swapneswarsundarray wants to merge 3 commits intoOpenAPITools:masterfrom
Closed
[BUG] Fix Patch operations reset fields to default if not specified #23650#23676swapneswarsundarray wants to merge 3 commits intoOpenAPITools:masterfrom
swapneswarsundarray wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
swapneswarsundarray
added a commit
to swapneswarsundarray/openapi-generator
that referenced
this pull request
May 2, 2026
Prevents sending default values in PATCH requests when fields are not explicitly set by the client. Only affects models starting with 'Patched'. Fixes OpenAPITools#23676
1d633da to
0a71bbb
Compare
Prevents sending default values in PATCH requests when fields are not explicitly set by the client. Only affects models starting with 'Patched'. Fixes OpenAPITools#23650
0a71bbb to
a3ec44e
Compare
…n to prevent broken output Fixed improper indentation in Mustache template that could cause broken Python code generation. Now uses inline conditions within method call instead of duplicated method blocks.
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.
Fixes #23650
Problem
In the Python generator, PATCH models were sending default values even when fields were not explicitly set by the client. This caused unintended updates where fields were reset to defaults.
Root Cause
The generated
to_dict()method usesexclude_none=True, which only skipsNonevalues but still includes fields with default values.Solution
Use
exclude_unset=Truefor PATCH models so that only explicitly set fields are included in the payload. Non-PATCH models continue usingexclude_none=Trueto avoid breaking existing behavior.Changes
model_generic.mustacheto conditionally useexclude_unset=Truefor PATCH modelsPythonClientCodegento detect PATCH models (based on naming convention) and set a flagImpact
PATCH requests now send only modified fields, preventing unintended resets. Behavior for non-PATCH models remains unchanged.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Fixes #23650. Python PATCH models now send only explicitly set fields for classes prefixed with
Patched, preventing defaults from overwriting existing data; non-PATCH behavior is unchanged. Also fixes template formatting to avoid broken Python output.model_generic.mustache, use inline conditional args inmodel_dump(...):exclude_unset=TrueforvendorExtensions.isPatchedModel, otherwiseexclude_none=True.PythonClientCodegen#postProcessModels, markPatched*models withisPatchedModelfor template handling.Written for commit 2d3bd2e. Summary will update on new commits.