mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
🐛 修复对 Pydantic V1 的适配
This commit is contained in:
@@ -3,6 +3,7 @@ from datetime import datetime
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from nonebot.adapters import Message
|
from nonebot.adapters import Message
|
||||||
|
from nonebot.compat import type_validate_json
|
||||||
from nonebot_plugin_orm import Model
|
from nonebot_plugin_orm import Model
|
||||||
from pydantic import BaseModel, ValidationError
|
from pydantic import BaseModel, ValidationError
|
||||||
from sqlalchemy import JSON, DateTime, Dialect, PickleType, String, TypeDecorator
|
from sqlalchemy import JSON, DateTime, Dialect, PickleType, String, TypeDecorator
|
||||||
@@ -30,7 +31,7 @@ class PydanticType(TypeDecorator):
|
|||||||
if isinstance(value, str | bytes):
|
if isinstance(value, str | bytes):
|
||||||
for i in self.get_model():
|
for i in self.get_model():
|
||||||
try:
|
try:
|
||||||
return i.model_validate_json(value)
|
return type_validate_json(i, value)
|
||||||
except ValidationError: # noqa: PERF203
|
except ValidationError: # noqa: PERF203
|
||||||
...
|
...
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|||||||
@@ -155,8 +155,8 @@ class Processor(ProcessorMeta):
|
|||||||
failover_code=[502],
|
failover_code=[502],
|
||||||
failover_exc=(TimeoutException,),
|
failover_exc=(TimeoutException,),
|
||||||
)
|
)
|
||||||
self.processed_data.user_profile[params] = UserProfile.model_validate_json(
|
self.processed_data.user_profile[params] = type_validate_json(
|
||||||
self.raw_response.user_profile[params]
|
UserProfile, self.raw_response.user_profile[params]
|
||||||
)
|
)
|
||||||
return self.processed_data.user_profile[params]
|
return self.processed_data.user_profile[params]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user