FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Initialize optional lists as UNSET, not [] by Robbie-Palmer · Pull Request #1346 · openapi-generators/openapi-python-client · GitHub

Repository navigation

fix: Initialize optional lists as UNSET, not [] - #1346

Merged
dbanty merged 1 commit into
openapi-generators:mainfrom
Robbie-Palmer:fix/optional-list-unset-1305
Oct 31, 2025
Merged

dbanty merged 1 commit into
openapi-generators:mainfrom
Robbie-Palmer:fix/optional-list-unset-1305

Conversation

Copy link
Copy Markdown
Contributor

Summary

Optional list properties were being incorrectly initialized with empty lists [] instead of UNSET when calling from_dict() with missing values. This breaks the semantic distinction between an omitted field and a field explicitly set to an empty list, which matters for PATCH operations and APIs that treat these cases differently.

Changes

The fix modifies the list_property.py.jinja template to:

  • Initialize optional list properties as UNSET with proper type annotations
  • Only create and populate lists when the source value is not UNSET
  • Preserve existing behavior for required list properties

Test Plan

  • All existing tests pass (417 tests)
  • Updated golden record snapshots to reflect the corrected behavior
  • Changes are minimal and focused on optional list properties only

Fixes #1305
Fixes #961

…n from_dict

Optional list properties were being initialized with empty lists [] instead
of UNSET when calling from_dict() with missing values. This caused unnecessary
empty arrays to be included in API request payloads.

The fix modifies the list_property.py.jinja template to:
- Initialize optional list properties as UNSET with proper type annotations
- Only create and populate lists when the source value is not UNSET
- Preserve existing behavior for required list properties

Fixes: openapi-generators#1305
Fixes: openapi-generators#961

dbanty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks great, thanks!

dbanty enabled auto-merge October 31, 2025 14:48
dbanty added this pull request to the merge queue Oct 31, 2025
Merged via the queue into openapi-generators:main with commit 30b27c2 Oct 31, 2025
knope-bot Bot mentioned this pull request Oct 31, 2025
Robbie-Palmer deleted the fix/optional-list-unset-1305 branch October 31, 2025 16:21
github-merge-queue Bot pushed a commit that referenced this pull request Nov 3, 2025
> [!IMPORTANT]
> Merging this pull request will create this release

## Fixes

- Remove non-existent CHANGELOG.md references from UV and Poetry
templates (#1344)
- Initialize optional lists as UNSET, not [] (#1346)
- Correct docstring typos in client template (#1347)
- Replace bare except blocks with specific exception types (#1348)

### Update `uv_build` to 0.9

#1352 by @johnthagen

`uv` has been in the `0.9.x` release cycle for a while, so update
templates to use the corresponding `uv_build` range.

Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
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

Labels

None yet

Projects

None yet

2 participants


Back | FazBrowse Home | New Git URL