Conversation
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
|
🧪 Testing To try out this version of the SDK, run: Expires: Mon, 06 Oct 2025 05:55:01 GMT |
c9e2f84 to
9df900b
Compare
9df900b to
ee565ee
Compare
ee565ee to
def43ef
Compare
def43ef to
aa80db5
Compare
aa80db5 to
a04fde7
Compare
a04fde7 to
a841dc4
Compare
| if PYDANTIC_V1: | ||
| field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast] | ||
| if not field_info: | ||
| continue | ||
|
|
||
| # Note: if one variant defines an alias then they all should | ||
| discriminator_alias = field.get("serialization_alias") | ||
|
|
||
| field_schema = field["schema"] | ||
| discriminator_alias = field_info.alias | ||
|
|
||
| if field_schema["type"] == "literal": | ||
| for entry in cast("LiteralSchema", field_schema)["expected"]: | ||
| if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation): | ||
| for entry in get_args(annotation): | ||
| if isinstance(entry, str): | ||
| mapping[entry] = variant | ||
| else: | ||
| field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast] | ||
| if not field_info: | ||
| field = _extract_field_schema_pv2(variant, discriminator_field_name) | ||
| if not field: | ||
| continue | ||
|
|
||
| # Note: if one variant defines an alias then they all should | ||
| discriminator_alias = field_info.alias | ||
| discriminator_alias = field.get("serialization_alias") | ||
|
|
||
| if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation): | ||
| for entry in get_args(annotation): | ||
| field_schema = field["schema"] | ||
|
|
||
| if field_schema["type"] == "literal": | ||
| for entry in cast("LiteralSchema", field_schema)["expected"]: | ||
| if isinstance(entry, str): | ||
| mapping[entry] = variant |
There was a problem hiding this comment.
There appears to be a logic error in the discriminated union handling code. The PYDANTIC_V1 and else branches have been swapped, but the internal logic within each branch wasn't updated to match.
In the current implementation:
- The
PYDANTIC_V1branch (lines 637-649) is attempting to access v2-style field schemas withfield['schema']andfield['serialization_alias'], butfield_infofrom Pydantic v1 doesn't have these attributes. - The
elsebranch (lines 650-662) is trying to access v1-style attributes likefield_info.aliason v2 field schemas.
This will cause AttributeError exceptions at runtime when processing discriminated unions. The code inside each conditional branch needs to be updated to match the correct Pydantic version it's handling.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
a841dc4 to
5ab5b4b
Compare
Automated Release PR
1.7.0 (2025-09-05)
Full Changelog: v1.6.1...v1.7.0
Features
Bug Fixes
Chores
pyproject.tomlfile (3f24a05)This pull request is managed by Stainless's GitHub App.
The semver version number is based on included commit messages. Alternatively, you can manually set the version number in the title of this pull request.
For a better experience, it is recommended to use either rebase-merge or squash-merge when merging this pull request.
🔗 Stainless website
📚 Read the docs
🙋 Reach out for help or questions