-
-
Notifications
You must be signed in to change notification settings - Fork 437
Fix bug in handling of graphql empty list defaults #2948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
koxudaxi
merged 6 commits into
koxudaxi:main
from
rpmcginty:bugfix/graphql-empty-list-default-bug
Jan 12, 2026
+140
−12
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e7fe359
adding tests to highlight the graphql bug
rpmcginty 0c5c6dd
fixing test to actually compare files (previously was not)
rpmcginty 90adc01
fix previous test that did not specify assert_func
rpmcginty 912af8c
Fix empty list default for GraphQL list fields
koxudaxi 8431860
Fix GraphQL empty list default handling
koxudaxi df9dd1e
Skip empty list default tests on black 22
koxudaxi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: empty_list_default.graphql | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| type Boolean = bool | ||
| """ | ||
| The `Boolean` scalar type represents `true` or `false`. | ||
| """ | ||
|
|
||
|
|
||
| type String = str | ||
| """ | ||
| The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. | ||
| """ | ||
|
|
||
|
|
||
| class Container(BaseModel): | ||
| name: String | ||
| typename__: Literal['Container'] | None = Field('Container', alias='__typename') | ||
|
|
||
|
|
||
| class PodSpec(BaseModel): | ||
| container_list: list[Container] = Field(default_factory=list) | ||
| container_list_or_none: list[Container | None] = Field(default_factory=list) | ||
| container_or_none_list_or_none: list[Container | None] | None = Field( | ||
| default_factory=list | ||
| ) | ||
| typename__: Literal['PodSpec'] | None = Field('PodSpec', alias='__typename') |
34 changes: 34 additions & 0 deletions
34
tests/data/expected/main/graphql/pydantic_v2_empty_list_default.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: empty_list_default.graphql | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| type Boolean = bool | ||
| """ | ||
| The `Boolean` scalar type represents `true` or `false`. | ||
| """ | ||
|
|
||
|
|
||
| type String = str | ||
| """ | ||
| The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. | ||
| """ | ||
|
|
||
|
|
||
| class Container(BaseModel): | ||
| name: String | ||
| typename__: Literal['Container'] | None = Field('Container', alias='__typename') | ||
|
|
||
|
|
||
| class PodSpec(BaseModel): | ||
| container_list: list[Container] = Field(default_factory=list) | ||
| container_list_or_none: list[Container | None] = Field(default_factory=list) | ||
| container_or_none_list_or_none: list[Container | None] | None = Field( | ||
| default_factory=list | ||
| ) | ||
| typename__: Literal['PodSpec'] | None = Field('PodSpec', alias='__typename') | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| input Container { | ||
| name: String! | ||
| } | ||
|
|
||
| input PodSpec { | ||
| container_list: [Container!]! = [] | ||
| container_list_or_none: [Container]! = [] | ||
| container_or_none_list_or_none: [Container] = [] | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.