GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: Initialize optional lists as UNSET, not [] by Robbie-Palmer · Pull Request #1346 · openapi-generators/openapi-python-client

Conversation

@Robbie-Palmer

@Robbie-Palmer Robbie-Palmer commented Oct 31, 2025

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

willsthompson reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@Robbie-Palmer
Fix optional list properties incorrectly initialized as empty lists i…
d82fb64
…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
dbanty approved these changes Oct 31, 2025
View reviewed changes

@dbanty dbanty left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Robbie-Palmer reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@dbanty
dbanty enabled auto-merge October 31, 2025 14:48
@dbanty
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 knope-bot Bot mentioned this pull request Oct 31, 2025
Release 0.27.1 #1345
Merged
@Robbie-Palmer
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
@knope-bot
Release 0.27.1 (#1345)
c41e22a
> [!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dbanty dbanty dbanty approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Optional array field generates with empty list [] instead of UNSET in from_dict method Optional property of type list is initialized with empty list instead of UNSET when using from_dict()

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Robbie-Palmer @dbanty
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.