Skip to content

fix: sdk label aliases#346

Closed
kenwoodjw wants to merge 8 commits into
langgenius:mainfrom
kenwoodjw:fix/sdk-label-aliases
Closed

fix: sdk label aliases#346
kenwoodjw wants to merge 8 commits into
langgenius:mainfrom
kenwoodjw:fix/sdk-label-aliases

Conversation

@kenwoodjw
Copy link
Copy Markdown
Contributor

Pull Request Checklist

Fixes ##345
Thank you for your contribution! Before submitting your PR, please make sure you have completed the following checks:

Compatibility Check

  • I have checked whether this change affects the backward compatibility of the plugin declared in README.md
  • I have checked whether this change affects the forward compatibility of the plugin declared in README.md
  • If this change introduces a breaking change, I have discussed it with the project maintainer and specified the release version in the README.md
  • I have described the compatibility impact and the corresponding version number in the PR description
  • I have checked whether the plugin version is updated in the README.md

Available Checks

  • just build has passed
  • Relevant documentation has been updated (if necessary)

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the I18nObject model to use standard camelCase/PascalCase-like attributes (en_US, zh_Hans, pt_BR, ja_JP) instead of lowercase ones, updating all references across the codebase and adding corresponding unit tests. A high-severity issue was identified in FormOption where overriding __init__ to set a default label fails under Pydantic v2 because validation occurs before the fallback logic is executed; using a @model_validator(mode="before") is recommended instead.

Comment on lines +68 to +71
def __init__(self, **data: object) -> None:
super().__init__(**data)
if not self.label:
self.label = I18nObject(en_us=self.value)
self.label = I18nObject(en_US=self.value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

In Pydantic v2, overriding __init__ to set default values for required fields (like label) does not work as expected. When super().__init__(**data) is called, Pydantic immediately validates the input data. If label is missing from data, a ValidationError is raised before the fallback logic if not self.label: can ever be reached. Conversely, if label is provided, self.label is already populated, making the fallback block dead code.\n\nTo fix this, we should use a @model_validator(mode="before") classmethod, similar to how it is done in ProviderModel and ParameterRule. This allows us to inject the fallback label into the input dictionary before Pydantic performs field validation.

    @model_validator(mode="before")\n    @classmethod\n    def validate_label(cls, data: dict) -> dict:\n        if isinstance(data, dict) and "value" in data and not data.get("label"):\n            data["label"] = I18nObject(en_US=str(data["value"]))\n        return data

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please review again

@kenwoodjw kenwoodjw changed the title Fix/sdk label aliases fix: sdk label aliases May 27, 2026
@kenwoodjw
Copy link
Copy Markdown
Contributor Author

@fatelei @crazywoola Please help review this PR.

@kenwoodjw kenwoodjw closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant