Skip to content

Commit

Permalink
fix: 修复模型验证字段的序列化与报错
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOrangeQWQ committed Sep 8, 2024
1 parent 4872ca2 commit 7efa68d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/plugins/publish/templates/render_error.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{{ error.msg }}<dt>请确保没有重复发布。</dt>
{% elif type == "plugin.test" %}
插件加载测试未通过。{{ detail_message("测试输出", ctx.output) }}
{% elif type == "metadata" %}
{% elif type == "plugin.metadata" %}
无法获取到插件元数据。<dt>{{ "请填写插件元数据" if ctx.plugin_test_result else "请确保插件正常加载" }}。</dt>
{% elif type == "plugin.type" %}
插件类型 {{ input }} 不符合规范。<dt>请确保插件类型正确,当前仅支持 application 与 library。</dt>
Expand Down
10 changes: 5 additions & 5 deletions src/utils/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def collect_valid_values(
raise PydanticCustomError("validation_context", "未获取到验证上下文")

result = handler(v)
if isinstance(result, BaseModel):
result = result.model_dump()
context["valid_data"][info.field_name] = result
return result

Expand Down Expand Up @@ -168,7 +170,7 @@ class PluginPublishInfo(PublishInfo, PyPIMixin):
"""插件支持的适配器"""
load: bool
""""插件测试结果"""
metadata: Metadata | None
metadata: Metadata
"""插件测试元数据"""

@field_validator("type", mode="before")
Expand Down Expand Up @@ -236,15 +238,13 @@ def plugin_test_load_validator(cls, v: bool, info: ValidationInfo) -> bool:
@field_validator("metadata", mode="before")
@classmethod
def plugin_test_metadata_validator(
cls, v: Metadata | None, info: ValidationInfo
) -> Metadata | None:
cls, v: Metadata, info: ValidationInfo
) -> Metadata:
context = info.context
if context is None:
raise PydanticCustomError("validation_context", "未获取到验证上下文")
if v is None:
raise PydanticCustomError("plugin.metadata", "插件缺少元数据")
if context.get("skip_plugin_test"):
return None
return v


Expand Down

0 comments on commit 7efa68d

Please sign in to comment.